Skip to content

standard lazy types#2788

Merged
matklad merged 15 commits intorust-lang:masterfrom
matklad:std-lazy
Mar 30, 2023
Merged

standard lazy types#2788
matklad merged 15 commits intorust-lang:masterfrom
matklad:std-lazy

Conversation

@matklad
Copy link
Copy Markdown
Contributor

@matklad matklad commented Oct 18, 2019

Add support for lazy initialized values to standard library, effectively superseding the popular lazy_static crate.

use std::sync::Lazy;

// `BACKTRACE` implements `Deref<Target = Option<String>>` 
// and is initialized on the first access
static BACKTRACE: Lazy<Option<String>> = Lazy::new(|| {
    std::env::var("RUST_BACKTRACE").ok()
});

Rendered

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-cell Proposals relating to interior mutability. A-sync Synchronization related proposals & ideas A-types-libstd Proposals & ideas introducing new types to the standard library. Libs-Tracked Libs issues that are tracked on the team's project board. T-libs-api Relevant to the library API team, which will review and decide on the RFC.

Projects

None yet

Development

Successfully merging this pull request may close these issues.