Last active
May 27, 2019 11:53
-
-
Save silphire/86d07f47798097dd4d575e6e0698eb66 to your computer and use it in GitHub Desktop.
mutability exercise
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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