Andy Balaam@diode.zoneOPtoAndy Balaam's programming lectures@diode.zone•Rust 101 - 4: Exercises for module A1
2·
9 months ago@maegul@lemmy.ml using sort
looks like a nice solution. For very large lists it will be doing more work than is strictly necessary, but for most use cases that would be great, and nice and simple.
@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 :-)