3 ms·
The difference has to do with ownership, and it has nothing to do with mutability. For both types, you can mutate them given a mutable refence, and you can't gi
by aliceryhl 4y ago
The difference has to do with ownership, and it has nothing to do with mutability. For both types, you can mutate them given a mutable refence, and you can't given an immutable reference.
For an example, an `&mut str` can be modified via various methods such as make_ascii_uppercase.
- sirwhinesalot 4y agoNope, not ownership either, Box<str> and String both own their memory, the different is fixed size vs growable :) But you're right, I edited my post to reflect this, the Java analogy is pretty strained as it is.
- Macha 4y agoI believe the parent poster was comparing &str and String, not Box<str> and String.
- sirwhinesalot 4y agoYeah in my original post (before the edit) I made a similar simplification with immutable vs mutable (since that's how they are commonly used), but the correct distinction is str vs String. You can have &str and &String and you can have &mut str and &mut String, and Box<str> and String. All cases exist.