diff options
| author | Trevor Gross <tmgross@umich.edu> | 2025-04-02 18:15:50 +0000 |
|---|---|---|
| committer | Trevor Gross <tmgross@umich.edu> | 2025-04-02 18:18:50 +0000 |
| commit | 072aa9e66f7c5e398d3030c8d41dc89079a4aed2 (patch) | |
| tree | 133a0fe9fac7256362dfcc0826cd401b9926111d /library/core/src | |
| parent | 4f0de4c81d80121ac7b576bc68d8016064f4d261 (diff) | |
| download | rust-072aa9e66f7c5e398d3030c8d41dc89079a4aed2.tar.gz rust-072aa9e66f7c5e398d3030c8d41dc89079a4aed2.zip | |
Apply requested API changes to `cell_update`
Do the following: * Switch to `impl FnOnce` rather than a generic `F`. * Change `update` to return nothing. This was discussed at a libs-api meeting [1]. Tracking issue: https://github.com/rust-lang/rust/issues/50186 [1]: https://github.com/rust-lang/rust/pull/134446#issuecomment-2770842949
Diffstat (limited to 'library/core/src')
| -rw-r--r-- | library/core/src/cell.rs | 15 |
1 files changed, 4 insertions, 11 deletions
diff --git a/library/core/src/cell.rs b/library/core/src/cell.rs index e789601a409..09117e4968d 100644 --- a/library/core/src/cell.rs +++ b/library/core/src/cell.rs @@ -544,7 +544,7 @@ impl<T: Copy> Cell<T> { unsafe { *self.value.get() } } - /// Updates the contained value using a function and returns the new value. + /// Updates the contained value using a function. /// /// # Examples /// @@ -554,21 +554,14 @@ impl<T: Copy> Cell<T> { /// use std::cell::Cell; /// /// let c = Cell::new(5); - /// let new = c.update(|x| x + 1); - /// - /// assert_eq!(new, 6); + /// c.update(|x| x + 1); /// assert_eq!(c.get(), 6); /// ``` #[inline] #[unstable(feature = "cell_update", issue = "50186")] - pub fn update<F>(&self, f: F) -> T - where - F: FnOnce(T) -> T, - { + pub fn update(&self, f: impl FnOnce(T) -> T) { let old = self.get(); - let new = f(old); - self.set(new); - new + self.set(f(old)); } } |
