We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 746a0f0 commit cc7698dCopy full SHA for cc7698d
examples/mutex_map.rs
@@ -0,0 +1,23 @@
1
+//! This example shows how to wrap a data structure in a mutex to achieve safe mutability.
2
+extern crate lazy_static;
3
+use lazy_static::lazy_static;
4
+use std::collections::HashMap;
5
+use std::sync::Mutex;
6
+
7
+lazy_static! {
8
+ static ref MUTEX_MAP: Mutex<HashMap<u32, &'static str>> = {
9
+ let mut m = HashMap::new();
10
+ m.insert(0, "foo");
11
+ m.insert(1, "bar");
12
+ m.insert(2, "baz");
13
+ Mutex::new(m)
14
+ };
15
+}
16
17
+fn main() {
18
+ MUTEX_MAP.lock().unwrap().insert(0, "boo");
19
+ println!(
20
+ "The entry for `0` is \"{}\".",
21
+ MUTEX_MAP.lock().unwrap().get(&0).unwrap()
22
+ );
23
0 commit comments