Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
struct SomeCollection {
strings: Vec<String>
}
impl SomeCollection {
pub fn new() -> Self {
SomeCollection { strings: Vec::new() }
}
pub fn insert(&mut self, s: String) {
self.strings.push(s);
}
pub fn print_all(&self) {
self.strings.iter().for_each(|item| println!("{}", item));
}
}
fn main() {
let mut my_collection = SomeCollection::new();
(0..10).for_each( |item| {
let value = format!("value number {}", item + 1);
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
You can’t perform that action at this time.