Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #[derive(Debug)]
- struct MyStruct{
- myval: usize
- }
- fn main() {
- let s = MyStruct{myval:1};
- println!("{:?}", change_it_2(s));
- }
- fn change_it_1(s: MyStruct) -> MyStruct {
- // s.myval=2; //cannot assign, compiler error!
- s
- }
- fn change_it_2(s: MyStruct) -> MyStruct {
- change_it_3(s) //Completly fine, s will be changed in change_it_3
- }
- fn change_it_3(mut s: MyStruct) -> MyStruct {
- s.myval = 2;
- s
- }
Add Comment
Please, Sign In to add comment