@UkiahSmith Im probably the wrong person to answer this, but in my understanding you are copying the value and creating a new variable ("Pass by Value"). In other languages (python?) that code would copy the reference to the original variable. ("Pass by Reference").

According to the Rust Book, the behavior may be different for variable types whose values are stored on the stack vs the heap. Eg: you used an int but try it with a string instead.

doc.rust-lang.org/book/ch04-01

Follow

@ike
Indeed, if you would want to get a reference, you would need to do &n or &mut n.
It is because numbers implement the Copy trait, which means code such as this would simply copy the entire value instead of moving it.
@UkiahSmith

Sign in to participate in the conversation
CleverLibre Social

CleverLibre Social is an inclusive social instance for open discussion, learning, and community.
All cultures welcome.
Hate speech and harassment strictly forbidden.