Skip to content

Instantly share code, notes, and snippets.

@willmurphyscode
Last active April 22, 2018 18:26
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/efa4178526c84f3f52a46ceb4a1a25b3 to your computer and use it in GitHub Desktop.
Save willmurphyscode/efa4178526c84f3f52a46ceb4a1a25b3 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);
}
pub fn print_all(&self) {
self.strings.iter().for_each(|item| println!("{}", item));
}
}
fn main() {
let mut values : Vec<String> = Vec::new();
let mut my_collection = SomeCollection::new();
(0..10).for_each( |item| {
let value = format!("value number {}", item + 1);
values.push(value);
});
values.iter().for_each(|value| my_collection.insert(&value));
my_collection.print_all();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment