Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sebglazebrook/cf7cdeb33c3ded897cccc1f50ea061c1 to your computer and use it in GitHub Desktop.
Save sebglazebrook/cf7cdeb33c3ded897cccc1f50ea061c1 to your computer and use it in GitHub Desktop.
struct Foo<'a> {
collection: Vec<usize>,
matches: Vec<&'a usize>,
}
impl<'a> Foo<'a> {
pub fn new() -> Self {
Foo { collection: vec![1,2,3,4,5,6] , matches: vec![] }
}
pub fn find_matches(&'a mut self) {
for item in &self.collection {
if item % 2 == 0 {
self.matches.push(&item);
}
}
for item in &self.matches {
println!("{:?}", item);
}
}
}
fn command() {
let mut foo = Foo::new();
foo.find_matches();
}
#[test]
fn it_works() {
command();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment