• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..--

patches/23-Nov-2023-6963

src/23-Nov-2023-307129

tests/23-Nov-2023-186142

.cargo_vcs_info.jsonD23-Nov-202374 65

.gitignoreD23-Nov-202329 54

Android.bpD23-Nov-20232.9 KiB10595

Cargo.tomlD23-Nov-20231.5 KiB4740

Cargo.toml.origD23-Nov-20231 KiB3526

LICENSED23-Nov-202310.6 KiB202169

LICENSE-APACHED23-Nov-202310.6 KiB202169

LICENSE-MITD23-Nov-20231 KiB2622

METADATAD23-Nov-2023407 2019

MODULE_LICENSE_APACHE2D23-Nov-20230

OWNERSD23-Nov-202340 21

README.mdD23-Nov-20232.6 KiB8054

TEST_MAPPINGD23-Nov-2023464 2423

cargo2android.jsonD23-Nov-2023226 1212

README.md

1lazy-static.rs
2==============
3
4A macro for declaring lazily evaluated statics in Rust.
5
6Using this macro, it is possible to have `static`s that require code to be
7executed at runtime in order to be initialized.
8This includes anything requiring heap allocations, like vectors or hash maps,
9as well as anything that requires non-const function calls to be computed.
10
11[![Travis-CI Status](https://travis-ci.com/rust-lang-nursery/lazy-static.rs.svg?branch=master)](https://travis-ci.com/rust-lang-nursery/lazy-static.rs)
12[![Latest version](https://img.shields.io/crates/v/lazy_static.svg)](https://crates.io/crates/lazy_static)
13[![Documentation](https://docs.rs/lazy_static/badge.svg)](https://docs.rs/lazy_static)
14[![License](https://img.shields.io/crates/l/lazy_static.svg)](https://github.com/rust-lang-nursery/lazy-static.rs#license)
15
16## Minimum supported `rustc`
17
18`1.27.2+`
19
20This version is explicitly tested in CI and may only be bumped in new minor versions. Any changes to the supported minimum version will be called out in the release notes.
21
22
23# Getting Started
24
25[lazy-static.rs is available on crates.io](https://crates.io/crates/lazy_static).
26It is recommended to look there for the newest released version, as well as links to the newest builds of the docs.
27
28At the point of the last update of this README, the latest published version could be used like this:
29
30Add the following dependency to your Cargo manifest...
31
32```toml
33[dependencies]
34lazy_static = "1.4.0"
35```
36
37...and see the [docs](https://docs.rs/lazy_static) for how to use it.
38
39# Example
40
41```rust
42#[macro_use]
43extern crate lazy_static;
44
45use std::collections::HashMap;
46
47lazy_static! {
48    static ref HASHMAP: HashMap<u32, &'static str> = {
49        let mut m = HashMap::new();
50        m.insert(0, "foo");
51        m.insert(1, "bar");
52        m.insert(2, "baz");
53        m
54    };
55}
56
57fn main() {
58    // First access to `HASHMAP` initializes it
59    println!("The entry for `0` is \"{}\".", HASHMAP.get(&0).unwrap());
60
61    // Any further access to `HASHMAP` just returns the computed value
62    println!("The entry for `1` is \"{}\".", HASHMAP.get(&1).unwrap());
63}
64```
65
66## License
67
68Licensed under either of
69
70 * Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
71 * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
72
73at your option.
74
75### Contribution
76
77Unless you explicitly state otherwise, any contribution intentionally submitted
78for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any
79additional terms or conditions.
80