Last active
February 3, 2026 20:19
-
-
Save dacr/cc2a879ab3fdc39e5957aa13f9b037c4 to your computer and use it in GitHub Desktop.
hello rust mutations / published by https://github.com/dacr/code-examples-manager #1a97069e-facd-4c5a-a52c-56dada02659e/53873e7d990ccc338d7259237d16fc4e5acef0e9
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
| #!/usr/bin/env rust-script | |
| // summary : hello rust mutations | |
| // keywords : rust, mutations, @testable | |
| // publish : gist | |
| // authors : David Crosson | |
| // license : Apache License Version 2.0 (https://www.apache.org/licenses/LICENSE-2.0.txt) | |
| // id : 1a97069e-facd-4c5a-a52c-56dada02659e | |
| // created-on : 2024-10-12T21:24:30+02:00 | |
| // managed-by : https://github.com/dacr/code-examples-manager | |
| // run-with : ./$file | |
| fn main() { | |
| // ------------------------------------- | |
| { | |
| let immutable_by_default = 32; | |
| let mut made_mutable = 42; | |
| made_mutable = 24; | |
| assert_eq!(immutable_by_default, 32); | |
| assert_eq!(made_mutable, 24); | |
| println!("{}", made_mutable); | |
| } | |
| // ------------------------------------- | |
| { | |
| let mut hello = "hello".to_string(); | |
| hello.push_str(" world"); // won't work without mut : | |
| hello = "world".to_string(); // won't work without mut : | |
| println!("`mut` mean both the reference AND the referenced content can be modified") | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment