Skip to content

Instantly share code, notes, and snippets.

@silphire
Last active May 27, 2019 11:53
Show Gist options
  • Save silphire/86d07f47798097dd4d575e6e0698eb66 to your computer and use it in GitHub Desktop.
Save silphire/86d07f47798097dd4d575e6e0698eb66 to your computer and use it in GitHub Desktop.
mutability exercise
struct Foo {
pub foo: Vec<isize>,
}
impl Foo {
pub fn get_foo(&self) -> &Vec<isize> {
return &self.foo;
}
pub fn get_foo_mut(&mut self) -> &mut Vec<isize> {
return &mut self.foo;
}
}
fn main() {
let a = Foo{foo: vec![1,2,3,4,5]};
for y in a.get_foo() {
print!("{} ", y);
}
println!();
for x in a.get_foo_mut() {
print!("{} ", x);
}
println!();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment