From b7505f79a46706561d93c81a6da8f305819ac7a4 Mon Sep 17 00:00:00 2001 From: Joshua Liebow-Feeser Date: Wed, 16 Aug 2023 17:00:08 -0700 Subject: [PATCH] Unalign::update docs suggest DerefMut (#273) For `T: Unaligned`, `Unalign: DerefMut`. Using that impl will usually be faster and more ergonomic than using `update`. Closes #262 --- src/lib.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 71ca0e2358..cbc37c9436 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1327,6 +1327,10 @@ impl Unalign { /// Updates the inner `T` by calling a function on it. /// + /// If [`T: Unaligned`], then `Unalign` implements [`DerefMut`], and that + /// impl should be preferred over this method when performing updates, as it + /// will usually be faster and more ergonomic. + /// /// For large types, this method may be expensive, as it requires copying /// `2 * size_of::()` bytes. \[1\] /// @@ -1334,6 +1338,8 @@ impl Unalign { /// invoke `f` on it directly. Instead, `update` moves it into a /// properly-aligned location in the local stack frame, calls `f` on it, and /// then moves it back to its original location in `self`. + /// + /// [`T: Unaligned`]: Unaligned pub fn update O>(&mut self, f: F) -> O { // On drop, this moves `copy` out of itself and uses `ptr::write` to // overwrite `slf`.