• Home
Name Date Size #Lines LOC

..--

compiletest/12-May-2024-10569

src/12-May-2024-306134

tests/12-May-2024-186142

.gitignoreD12-May-202429 54

.travis.ymlD12-May-2024914 3532

BUILD.gnD12-May-20241,001 2824

Cargo.tomlD12-May-20241 KiB3526

LICENSE-APACHED12-May-202410.6 KiB202169

LICENSE-MITD12-May-20241 KiB2622

README.OpenSourceD12-May-2024354 1111

README.mdD12-May-20242.6 KiB8054

appveyor.ymlD12-May-20241.8 KiB6249

README.OpenSource

1[
2  {
3    "Name": "lazy-static.rs",
4    "License": "Apache License V2.0, MIT",
5    "License File": "LICENSE-APACHE, LICENSE-MIT",
6    "Version Number": "1.3.0",
7    "Owner": "fangting12@huawei.com",
8    "Upstream URL": "https://github.com/rust-lang-nursery/lazy-static.rs",
9    "Description": "A Rust library that provides a lazy-initialized cell."
10  }
11]

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