49 ms·
> Getters return values. This returns a pointer. So it's an accessor. With unchecked semantics. This isn't exactly a pointer: Rust distinguishes between read-o
by two_handfuls 2y ago
> Getters return values. This returns a pointer. So it's an accessor. With unchecked semantics.
This isn't exactly a pointer: Rust distinguishes between read-only and mutable ("exclusive") references.
This returns a read-only reference, so it's very much like a getter: you cannot use it to modify the thing it points to.
It's just that it does it without a copy, which matters for performance in some cases.
- 0x457 2y agoTo be clear, you can add `get_x_mut()` and return mutable/exclusive reference that can be used to mutate the field behind it. It's not the same as a setter in this case.