Skip to content

Commit 5ac0bd0

Browse files
committed
Mention the ambiguity between getters and conversions
1 parent b192254 commit 5ac0bd0

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/naming.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,16 @@ unsafe fn get_unchecked(&self, index: K) -> &V;
167167
unsafe fn get_unchecked_mut(&mut self, index: K) -> &mut V;
168168
```
169169

170+
The difference between getters and conversions ([C-CONV](#c-conv)) can be subtle
171+
and is not always clear-cut. For example [`TempDir::path`] can be understood as
172+
a getter for the filesystem path of the temporary directory, while
173+
[`TempDir::into_path`] is a conversion that transfers responsibility for
174+
deleting the temporary directory to the caller. Since `path` is a getter, it
175+
would not be correct to call it `get_path` or `as_path`.
176+
177+
[`TempDir::path`]: https://docs.rs/tempdir/0.3.5/tempdir/struct.TempDir.html#method.path
178+
[`TempDir::into_path`]: https://docs.rs/tempdir/0.3.5/tempdir/struct.TempDir.html#method.into_path
179+
170180
### Examples from the standard library
171181

172182
- [`std::io::Cursor::get_mut`](https://doc.rust-lang.org/std/io/struct.Cursor.html#method.get_mut)

0 commit comments

Comments
 (0)