Guest User

Untitled

a guest
Jul 18th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. use std::rc::Rc;
  2. use std::collections::HashMap;
  3.  
  4. struct Message<'a> {
  5. user: &'a User,
  6. text: String,
  7. // timestamp, etc.
  8. }
  9.  
  10. struct User {
  11. // Actually a VecDeque, but Vec for simplicity
  12. messages: Vec<Rc<Message<'static>>>,
  13. username: String,
  14. // other info
  15. }
  16.  
  17. struct Context {
  18. messages: Vec<Rc<Message<'static>>>,
  19. users: HashMap<String, User>,
  20. }
  21.  
  22. // Both Context and User outlive Messages
  23. // Both Context and User have references to Messages
  24. // Context outlives Users (Here, by owning User)
  25.  
  26. // No matter who owns what (Context directly owns Messages/etc) the same sort of issues arise
  27.  
  28. fn main() {}
Add Comment
Please, Sign In to add comment