- cross-posted to:
- learningrustandlemmy
- cross-posted to:
- learningrustandlemmy
Going through some exercises on basic Rust syntax and ownership.
Links:
- Exercises: https://101-rs.tweede.golf/A1-language-basics/mod.html
- Slides: http://artificialworlds.net/presentations/rust-101/A1-intro-to-rust
Rust 101 is a series of videos explaining how to write programs in Rust. The course materials for this series are developed by tweede golf. You can find more information at https://github.com/tweedegolf/101-rs and you can sponsor the work at https://github.com/sponsors/tweedegolf . They are released under the Creative Commons Attribution Share Alike 4.0 International license.
This series of videos is copyright 2023 Andy Balaam and the tweede golf contributors and is released under the Creative Commons Attribution Share Alike 4.0 International license.
@maegul@lemmy.ml Yeah if you wanted to modify the original variable you would need to make it mutable, and use
&mut
references to it all the way down. By changing the function parameter to be mutable, we’re not modifying anything outside of this function: we’re just allowing ourselves to re-use the parameter to hold different values while the function is running. I don’t particularly like doing that - I’d prefer to make a new local variable if I want to change things within the function, but I think the exercise might have said I wasn’t allowed to make new variables :-)Cheers Andy!
Also sorry for the gobbled English in my question! Thanks for making sense of it!