Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. use std::sync::{Arc, Mutex};
  2.  
  3. struct MyStruct
  4. {
  5. pub field1: Option<Vec<String>>
  6. }
  7.  
  8. impl MyStruct
  9. {
  10. pub fn new() -> Self
  11. {
  12. Self
  13. {
  14. field1: None,
  15. }
  16. }
  17.  
  18. pub fn new_arc_mutex() -> Arc<Mutex<Self>>
  19. {
  20. Arc::new(Mutex::new(Self::new()))
  21. }
  22. }
  23.  
  24. fn main()
  25. {
  26. let ms = MyStruct::new_arc_mutex();
  27.  
  28. let mut ms = ms.lock().unwrap();
  29. ms.field1 = Some(vec!());
  30.  
  31. let mut v = ms.field1.as_mut();
  32. match v {
  33. Some(val) => val.push("Hello World!".to_owned()),
  34. None => {}
  35. }
  36.  
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement