-
-
Save hoodie/6b65bcb7667f8bdcd50b to your computer and use it in GitHub Desktop.
Shared via Rust Playground
This file contains hidden or 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
#[derive(Debug)] | |
struct Pair(i32,i32); | |
fn eat(y:&mut Pair) { y.0 = 1; y.1 = 2} | |
//fn replace(y:&mut Pair) { y = Pair(1,2)} // no? why not? | |
fn replace(y:&mut Pair) { let Pair(x,z) = Pair(1,2); y.0 = x; y.1 = z} | |
fn main(){ | |
let mut p = Pair(5,6); | |
let mut q = Pair(5,6); | |
eat(&mut p); | |
replace(&mut q); | |
//println!("{:?}", x); | |
println!("{:?}", p); | |
println!("{:?}", q); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment