File tree Expand file tree Collapse file tree 2 files changed +24
-1
lines changed
Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change 33 include :
44 - rust : 1.27.2
55 script :
6- - cargo test --all-targets
6+ - cargo test --tests
77 - rust : stable
88 script :
99 - cargo test
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments