Skip to content

Instantly share code, notes, and snippets.

@andyjsbell
Created July 20, 2020 15:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andyjsbell/1afe2dd76f7ee0bf796fe8ab7e7d607e to your computer and use it in GitHub Desktop.
Save andyjsbell/1afe2dd76f7ee0bf796fe8ab7e7d607e to your computer and use it in GitHub Desktop.
struct Store<'a> {
items: Vec<&'a Item>,
}
struct Item {
name: String,
}
impl<'a> Store<'a> {
pub fn new() -> Self {
Store { items: Vec::new() }
}
pub fn add(&mut self, item: &'a Item) {
self.items.push(item)
}
}
impl Item {
pub fn new(name: String) -> Self {
Item { name }
}
pub fn printme(&self) {
println!("{}", self.name)
}
}
struct Controller<'a> {
item: Item,
store: Store<'a>,
}
impl<'a> Controller<'a> {
pub fn new() -> Self {
Controller {
item: Item::new(String::from("test")),
store: Store::new(),
}
}
pub fn connect(&'a mut self) {
self.store.add(&self.item)
}
pub fn fire(&self) {
}
}
pub fn main() {
println!("hello");
let mut controller = Controller::new();
controller.connect();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment