Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::sync::{Arc, Mutex};
- struct MyStruct
- {
- pub field1: Option<Vec<String>>
- }
- impl MyStruct
- {
- pub fn new() -> Self
- {
- Self
- {
- field1: None,
- }
- }
- pub fn new_arc_mutex() -> Arc<Mutex<Self>>
- {
- Arc::new(Mutex::new(Self::new()))
- }
- }
- fn main()
- {
- let ms = MyStruct::new_arc_mutex();
- let mut ms = ms.lock().unwrap();
- ms.field1 = Some(vec!());
- let v = ms.field1.as_mut().unwrap();
- (*v).push("Hello World!".to_owned());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement