> Creating new objects in functions and returning them should be avoided if possible. It's a Rust idiom to create the object in the caller and pass it into a function to be modified.
> immutability is the default
Haven't yet written any Rust code, but aren't those two things contradicting each other? I'd have thought that with immutability the most natural way to operate is to do pure functions (for uninitiated: pure function doesn't modify anything, can only produce new things).
> Haven't yet written any Rust code, but aren't those two things contradicting each other?
I don't think so.
One way to ensure that data isn't mutated by different parts of a program,
is to have immutable data structures.
The other way - the Rust way - is to seriously track who holds mutable
references to the same data and just not allow it.
So you can have more optimized mutable data structures, but can be sure,
that if you're holding a mutable reference, that no other can modify
the data during the lifetime/scope of your mutable reference.
> immutability is the default
Haven't yet written any Rust code, but aren't those two things contradicting each other? I'd have thought that with immutability the most natural way to operate is to do pure functions (for uninitiated: pure function doesn't modify anything, can only produce new things).