Skip to content

Commit a29a841

Browse files
committed
Incorporate getter/setter names from RFC 344
1 parent 1b1ac21 commit a29a841

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

style/naming/README.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,22 @@ mod foo {
8686
This convention avoids stuttering (like `io::IoError`). Library clients can
8787
rename on import to avoid clashes.
8888

89-
### Getter/setter methods [FIXME]
89+
### Getter/setter methods [RFC 344]
9090

91-
> **[FIXME]** Need a naming and signature convention here.
91+
> The guidelines below were approved by [RFC #344](https://github.com/rust-lang/rfcs/pull/344).
92+
93+
Some data structures do not wish to provide direct access to their fields, but
94+
instead offer "getter" and "setter" methods for manipulating the field state
95+
(often providing checking or other functionality).
96+
97+
The convention for a field `foo: T` is:
98+
99+
* A method `foo(&self) -> &T` for getting the current value of the field.
100+
* A method `set_foo(&self, val: T)` for setting the field. (The `val` argument
101+
here may take `&T` or some other type, depending on the context.)
102+
103+
Note that this convention is about getters/setters on ordinary data types, *not*
104+
on [builder objects](../ownership/builders.html).
92105

93106
### Escape hatches [FIXME]
94107

0 commit comments

Comments
 (0)