Created
February 22, 2016 19:17
-
-
Save apopiak/261c610c5a8e86fa971a to your computer and use it in GitHub Desktop.
Rust mutability example
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
fn main() { | |
let mut val: i32 = 1; // veränderbare Variable (mit festem Wert) | |
val = 2; // ok | |
let foo: &mut i32 = &mut 2; // fest Referenz auf einen veränderbaren Wert | |
*foo = 3; // ok | |
foo = &mut val; // not ok | |
let wub = 6; // feste Referenz auf einen festen Wert | |
let mut bar: & i32 = & 4; // veränderbare Referenz mit festem Wert | |
*bar = 5; // not ok | |
bar = & wub; // ok | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment