Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::rc::Rc;
- use std::collections::HashMap;
- struct Message<'a> {
- user: &'a User,
- text: String,
- // timestamp, etc.
- }
- struct User {
- // Actually a VecDeque, but Vec for simplicity
- messages: Vec<Rc<Message<'static>>>,
- username: String,
- // other info
- }
- struct Context {
- messages: Vec<Rc<Message<'static>>>,
- users: HashMap<String, User>,
- }
- // Both Context and User outlive Messages
- // Both Context and User have references to Messages
- // Context outlives Users (Here, by owning User)
- // No matter who owns what (Context directly owns Messages/etc) the same sort of issues arise
- fn main() {}
Add Comment
Please, Sign In to add comment