]> git.proxmox.com Git - rustc.git/blame - src/vendor/lazy_static/README.md
New upstream version 1.19.0+dfsg1
[rustc.git] / src / vendor / lazy_static / README.md
CommitLineData
8bb4bdeb
XL
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.org/rust-lang-nursery/lazy-static.rs.svg?branch=master)](https://travis-ci.org/rust-lang-nursery/lazy-static.rs)
12
13# Getting Started
14
15[lazy-static.rs is available on crates.io](https://crates.io/crates/lazy_static).
16It is recommended to look there for the newest released version, as well as links to the newest builds of the docs.
17
18At the point of the last update of this README, the latest published version could be used like this:
19
20Add the following dependency to your Cargo manifest...
21
22```toml
23[dependencies]
24lazy_static = "0.2"
25```
26
27...and see the [docs](http://rust-lang-nursery.github.io/lazy-static.rs/lazy_static/index.html) for how to use it.
28
29# Example
30
31```rust
32#[macro_use]
33extern crate lazy_static;
34
35use std::collections::HashMap;
36
37lazy_static! {
38 static ref HASHMAP: HashMap<u32, &'static str> = {
39 let mut m = HashMap::new();
40 m.insert(0, "foo");
41 m.insert(1, "bar");
42 m.insert(2, "baz");
43 m
44 };
45}
46
47fn main() {
48 // First access to `HASHMAP` initializes it
49 println!("The entry for `0` is \"{}\".", HASHMAP.get(&0).unwrap());
50
51 // Any further access to `HASHMAP` just returns the computed value
52 println!("The entry for `1` is \"{}\".", HASHMAP.get(&1).unwrap());
53}
54```
7cac9316
XL
55
56## License
57
58Licensed under either of
59
60 * Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
61 * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
62
63at your option.
64
65### Contribution
66
67Unless you explicitly state otherwise, any contribution intentionally submitted
68for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any
69additional terms or conditions.