Idiomatic naming for getters/setters


#1

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_?


#2

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.


#3

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


#4

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


#5

Thanks!