Hacker Timesnew | past | comments | ask | show | jobs | submitlogin

> 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.



To 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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: