Skip to content

Instantly share code, notes, and snippets.

@willmurphyscode
Created April 20, 2018 11:42
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 willmurphyscode/f348c4006033484af6d410573c198d50 to your computer and use it in GitHub Desktop.
Save willmurphyscode/f348c4006033484af6d410573c198d50 to your computer and use it in GitHub Desktop.
struct SomeCollection<'a> {
strings: Vec<&'a str>
}
impl<'a> SomeCollection<'a> {
pub fn new() -> Self {
SomeCollection { strings: Vec::new() }
}
pub fn insert(&mut self, s: &'a str) {
self.strings.push(s);
}
}
fn main() {
let mut my_collection = SomeCollection::new();
(0..10).for_each( |item| {
let value = format!("value number {}", item + 1);
my_collection.insert(&value);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment