Sha256: dc011598c2a2e920846870848a8a4fd323449a69bf97b56083d760cee22e6406

Contents?: true

Size: 606 Bytes

Versions: 12

Compression:

Stored size: 606 Bytes

Contents

//! This example shows how to wrap a data structure in a mutex to achieve safe mutability.
extern crate lazy_static;
use lazy_static::lazy_static;
use std::collections::HashMap;
use std::sync::Mutex;

lazy_static! {
    static ref MUTEX_MAP: Mutex<HashMap<u32, &'static str>> = {
        let mut m = HashMap::new();
        m.insert(0, "foo");
        m.insert(1, "bar");
        m.insert(2, "baz");
        Mutex::new(m)
    };
}

fn main() {
    MUTEX_MAP.lock().unwrap().insert(0, "boo");
    println!(
        "The entry for `0` is \"{}\".",
        MUTEX_MAP.lock().unwrap().get(&0).unwrap()
    );
}

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
wasmtime-29.0.0 ./ext/cargo-vendor/lazy_static-1.5.0/examples/mutex_map.rs
wasmtime-28.0.0 ./ext/cargo-vendor/lazy_static-1.5.0/examples/mutex_map.rs
wasmtime-27.0.0 ./ext/cargo-vendor/lazy_static-1.5.0/examples/mutex_map.rs
wasmtime-26.0.0 ./ext/cargo-vendor/lazy_static-1.5.0/examples/mutex_map.rs
wasmtime-25.0.2 ./ext/cargo-vendor/lazy_static-1.5.0/examples/mutex_map.rs
wasmtime-25.0.1 ./ext/cargo-vendor/lazy_static-1.5.0/examples/mutex_map.rs
wasmtime-25.0.0 ./ext/cargo-vendor/lazy_static-1.5.0/examples/mutex_map.rs
wasmtime-24.0.0 ./ext/cargo-vendor/lazy_static-1.5.0/examples/mutex_map.rs
wasmtime-23.0.2 ./ext/cargo-vendor/lazy_static-1.5.0/examples/mutex_map.rs
wasmtime-22.0.0 ./ext/cargo-vendor/lazy_static-1.5.0/examples/mutex_map.rs
wasmtime-21.0.1 ./ext/cargo-vendor/lazy_static-1.5.0/examples/mutex_map.rs
wasmtime-20.0.2 ./ext/cargo-vendor/lazy_static-1.5.0/examples/mutex_map.rs