Advertisement
Guest User

Untitled

a guest
Apr 25th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. use std::collections::HashMap;
  2.  
  3. #[derive(Debug)]
  4. struct Child(String);
  5.  
  6. #[derive(Debug)]
  7. struct Parent<'a> {
  8. s: HashMap<String, &'a Child>
  9. }
  10.  
  11. impl<'a> Parent<'a> {
  12. fn new() -> Parent<'a> {
  13. Parent {
  14. s: HashMap::new()
  15. }
  16. }
  17.  
  18. fn s_mut(&mut self) -> &mut HashMap<String, &'a Child> {
  19. &mut self.s
  20. }
  21. }
  22.  
  23. fn main() {
  24. let c = Child("a".to_string());
  25. let mut p = Parent::new();
  26. p.s_mut().insert("k".to_string(), &c);
  27. println!("{:?}", p);
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement