Idiomatic naming for getters/setters


In coreaudio-rs, we’re wrapping mutable objects OOP-style, and currently there are some getters/setters with inconsistent naming.

I have a feeling I see this pattern often in other Rust code: set_x for setters, and simply x (with no prefix) for getters. Is this generally accepted as the way to go, or is it set_/get_?


I did find some examples of this in the standard lib:

But that’s still not very many, and a lot of crates tend to use either one.


Yes, RFC #344 says that the conventions should be foo for the getter and set_foo for the setter.


Nice! I hadn’t yet seen this RFC, thanks for the link.