@@ -126,6 +126,57 @@ fn as_mut_slice(&mut self) -> &mut [T];
126
126
- [ ` Option::into_iter ` ] ( https://doc.rust-lang.org/std/option/enum.Option.html#method.into_iter )
127
127
128
128
129
+ <a id =" c-getter " ></a >
130
+ ## Getter names follow Rust convention (C-GETTER)
131
+
132
+ With a few exceptions, the ` get_ ` prefix is not used for getters in Rust code.
133
+
134
+ ``` rust
135
+ pub struct S {
136
+ first : First ,
137
+ second : Second ,
138
+ }
139
+
140
+ impl S {
141
+ // Not get_first.
142
+ pub fn first (& self ) -> & First {
143
+ & self . first
144
+ }
145
+
146
+ // Not get_first_mut, get_mut_first, or mut_first.
147
+ pub fn first_mut (& mut self ) -> & mut First {
148
+ & mut self . first
149
+ }
150
+ }
151
+ ```
152
+
153
+ The ` get ` naming is used only when there is a single and obvious thing that
154
+ could reasonably be gotten by a getter. For example [ ` Cell::get ` ] accesses the
155
+ content of a ` Cell ` .
156
+
157
+ [ `Cell::get` ] : https://doc.rust-lang.org/std/cell/struct.Cell.html#method.get
158
+
159
+ For getters that do runtime validation such as bounds checking, consider adding
160
+ unsafe ` _unchecked ` variants. Typically those will have the following
161
+ signatures.
162
+
163
+ ``` rust
164
+ fn get (& self , index : K ) -> Option <& V >;
165
+ fn get_mut (& mut self , index : K ) -> Option <& mut V >;
166
+ unsafe fn get_unchecked (& self , index : K ) -> & V ;
167
+ unsafe fn get_unchecked_mut (& mut self , index : K ) -> & mut V ;
168
+ ```
169
+
170
+ ### Examples from the standard library
171
+
172
+ - [ ` std::io::Cursor::get_mut ` ] ( https://doc.rust-lang.org/std/io/struct.Cursor.html#method.get_mut )
173
+ - [ ` std::ptr::Unique::get_mut ` ] ( https://doc.rust-lang.org/std/ptr/struct.Unique.html#method.get_mut )
174
+ - [ ` std::sync::PoisonError::get_mut ` ] ( https://doc.rust-lang.org/std/sync/struct.PoisonError.html#method.get_mut )
175
+ - [ ` std::sync::atomic::AtomicBool::get_mut ` ] ( https://doc.rust-lang.org/std/sync/atomic/struct.AtomicBool.html#method.get_mut )
176
+ - [ ` std::collections::hash_map::OccupiedEntry::get_mut ` ] ( https://doc.rust-lang.org/std/collections/hash_map/struct.OccupiedEntry.html#method.get_mut )
177
+ - [ ` <[T]>::get_unchecked ` ] ( https://doc.rust-lang.org/std/primitive.slice.html#method.get_unchecked )
178
+
179
+
129
180
<a id =" c-iter " ></a >
130
181
## Methods on collections that produce iterators follow ` iter ` , ` iter_mut ` , ` into_iter ` (C-ITER)
131
182
@@ -203,57 +254,6 @@ example [`vec::IntoIter`].
203
254
[btree_map :: Values ]: https : // doc.rust-lang.org/std/collections/btree_map/struct.Values.html
204
255
205
256
206
- <a id = " c-getter" ></ a >
207
- ## Getter names follow Rust convention (C - GETTER )
208
-
209
- With a few exceptions , the `get_ ` prefix is not used for getters in Rust code .
210
-
211
- ```rust
212
- pub struct S {
213
- first : First ,
214
- second : Second ,
215
- }
216
-
217
- impl S {
218
- // Not get_first.
219
- pub fn first (& self ) -> & First {
220
- & self . first
221
- }
222
-
223
- // Not get_first_mut, get_mut_first, or mut_first.
224
- pub fn first_mut (& mut self ) -> & mut First {
225
- & mut self . first
226
- }
227
- }
228
- ```
229
-
230
- The ` get ` naming is used only when there is a single and obvious thing that
231
- could reasonably be gotten by a getter. For example [ ` Cell::get ` ] accesses the
232
- content of a ` Cell ` .
233
-
234
- [ `Cell::get` ] : https://doc.rust-lang.org/std/cell/struct.Cell.html#method.get
235
-
236
- For getters that do runtime validation such as bounds checking, consider adding
237
- unsafe ` _unchecked ` variants. Typically those will have the following
238
- signatures.
239
-
240
- ``` rust
241
- fn get (& self , index : K ) -> Option <& V >;
242
- fn get_mut (& mut self , index : K ) -> Option <& mut V >;
243
- unsafe fn get_unchecked (& self , index : K ) -> & V ;
244
- unsafe fn get_unchecked_mut (& mut self , index : K ) -> & mut V ;
245
- ```
246
-
247
- ### Examples from the standard library
248
-
249
- - [ ` std::io::Cursor::get_mut ` ] ( https://doc.rust-lang.org/std/io/struct.Cursor.html#method.get_mut )
250
- - [ ` std::ptr::Unique::get_mut ` ] ( https://doc.rust-lang.org/std/ptr/struct.Unique.html#method.get_mut )
251
- - [ ` std::sync::PoisonError::get_mut ` ] ( https://doc.rust-lang.org/std/sync/struct.PoisonError.html#method.get_mut )
252
- - [ ` std::sync::atomic::AtomicBool::get_mut ` ] ( https://doc.rust-lang.org/std/sync/atomic/struct.AtomicBool.html#method.get_mut )
253
- - [ ` std::collections::hash_map::OccupiedEntry::get_mut ` ] ( https://doc.rust-lang.org/std/collections/hash_map/struct.OccupiedEntry.html#method.get_mut )
254
- - [ ` <[T]>::get_unchecked ` ] ( https://doc.rust-lang.org/std/primitive.slice.html#method.get_unchecked )
255
-
256
-
257
257
<a id = " c-feature" ></ a >
258
258
## Feature names are free of placeholder words (C - FEATURE )
259
259
0 commit comments