Skip to content

Commit b7505f7

Browse files
authored
Unalign::update docs suggest DerefMut (#273)
For `T: Unaligned`, `Unalign<T>: DerefMut`. Using that impl will usually be faster and more ergonomic than using `update`. Closes #262
1 parent 4b32941 commit b7505f7

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,13 +1327,19 @@ impl<T> Unalign<T> {
13271327

13281328
/// Updates the inner `T` by calling a function on it.
13291329
///
1330+
/// If [`T: Unaligned`], then `Unalign<T>` implements [`DerefMut`], and that
1331+
/// impl should be preferred over this method when performing updates, as it
1332+
/// will usually be faster and more ergonomic.
1333+
///
13301334
/// For large types, this method may be expensive, as it requires copying
13311335
/// `2 * size_of::<T>()` bytes. \[1\]
13321336
///
13331337
/// \[1\] Since the inner `T` may not be aligned, it would not be sound to
13341338
/// invoke `f` on it directly. Instead, `update` moves it into a
13351339
/// properly-aligned location in the local stack frame, calls `f` on it, and
13361340
/// then moves it back to its original location in `self`.
1341+
///
1342+
/// [`T: Unaligned`]: Unaligned
13371343
pub fn update<O, F: FnOnce(&mut T) -> O>(&mut self, f: F) -> O {
13381344
// On drop, this moves `copy` out of itself and uses `ptr::write` to
13391345
// overwrite `slf`.

0 commit comments

Comments
 (0)