From ca427530d3434d788bde881920ef3925c9530d86 Mon Sep 17 00:00:00 2001 From: Christopher Regali Date: Thu, 12 Jan 2023 20:27:39 +0100 Subject: [PATCH] Rename trait member function to make naming more consistent --- src/immediatevalue.rs | 16 ++++++++-------- src/lazyvalue.rs | 4 ++-- src/lazyvec.rs | 4 ++-- src/lib.rs | 6 +++--- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/immediatevalue.rs b/src/immediatevalue.rs index a873b11..7a7b3fb 100644 --- a/src/immediatevalue.rs +++ b/src/immediatevalue.rs @@ -33,7 +33,7 @@ impl Deref for BoxedSendError { /// [`ImmediateValuePromise::get_state`] which also yields an [`ImmediateValueState`] but without requiring `mut`. /// Another useful feature after calculation is finished, /// is that you can use [`ImmediateValuePromise::poll_state_mut`] to get a mutable [`ImmediateValueState`] -/// which allows you to take ownership of inner values with [`ImmediateValueState::take_inner`] or get a mutable reference +/// which allows you to take ownership of inner values with [`ImmediateValueState::take_value`] or get a mutable reference /// to the inner via [`ImmediateValueState::get_value_mut`]. /// ## Examples /// ### Basic usage @@ -87,7 +87,7 @@ impl Deref for BoxedSendError { /// } /// assert!(result.get_value_mut().is_some()); /// // take it out -/// let value = result.take_inner(); +/// let value = result.take_value(); /// assert_eq!(value.unwrap(), 32); /// ``` /// ### Optional laziness @@ -154,7 +154,7 @@ impl DirectCacheAccess for ImmediateValueState { /// Takes ownership of the inner value if ready, leaving self in state [`ImmediateValueState::Empty`]. /// Does nothing if we are in any other state. - fn take_inner(&mut self) -> Option { + fn take_value(&mut self) -> Option { if matches!(self, ImmediateValueState::Success(_)) { let val = mem::replace(self, ImmediateValueState::Empty); return match val { @@ -173,8 +173,8 @@ impl DirectCacheAccess for ImmediateValuePromise { fn get_value(&self) -> Option<&T> { self.state.get_value() } - fn take_inner(&mut self) -> Option { - self.state.take_inner() + fn take_value(&mut self) -> Option { + self.state.take_value() } } @@ -306,7 +306,7 @@ mod test { } let result = oneshot_val.poll_state_mut(); // take it out, should be changed and owned - let value = result.take_inner(); + let value = result.take_value(); assert_eq!(value.unwrap().as_str(), "changed"); assert!(matches!(result, ImmediateValueState::Empty)); } @@ -331,12 +331,12 @@ mod test { option.as_mut().unwrap().poll_state(); let _inner = option.get_value(); let _inner_mut = option.get_value_mut(); - let inner_owned = option.take_inner().unwrap(); + let inner_owned = option.take_value().unwrap(); assert_eq!(inner_owned, "bla"); // after value is taken, we can't borrow it again assert!(option.get_value().is_none()); assert!(option.get_value_mut().is_none()); - assert!(option.take_inner().is_none()); + assert!(option.take_value().is_none()); }); } } diff --git a/src/lazyvalue.rs b/src/lazyvalue.rs index 376ac11..fdd37d0 100644 --- a/src/lazyvalue.rs +++ b/src/lazyvalue.rs @@ -85,7 +85,7 @@ impl DirectCacheAccess for LazyValuePromise { /// takes the current value, if data was [`DataState::UpToDate`] it returns the value and sets the state to /// [`DataState::Uninitialized`]. Otherwise, returns None. - fn take_inner(&mut self) -> Option { + fn take_value(&mut self) -> Option { if self.state == DataState::UpToDate { self.state = DataState::Uninitialized; self.cache.take() @@ -214,7 +214,7 @@ mod test { let val = delayed_value.get_value(); assert_eq!(*val.unwrap(), 42); let _val_mut = delayed_value.get_value_mut(); - let value_owned = delayed_value.take_inner().unwrap(); + let value_owned = delayed_value.take_value().unwrap(); assert_eq!(value_owned, 42); assert!(delayed_value.is_uninitialized()); }); diff --git a/src/lazyvec.rs b/src/lazyvec.rs index 0981173..61cc42f 100644 --- a/src/lazyvec.rs +++ b/src/lazyvec.rs @@ -103,7 +103,7 @@ impl DirectCacheAccess> for LazyVecPromise { /// Take the current data. If state was [`DataState::UpToDate`] it will return the value. /// If the state was anything else, it will return None. If data is taken successfully, will leave /// the object in state [`DataState::Uninitialized`] - fn take_inner(&mut self) -> Option> { + fn take_value(&mut self) -> Option> { if self.state == DataState::UpToDate { self.state = DataState::Uninitialized; Some(mem::take(&mut self.data)) @@ -242,7 +242,7 @@ mod test { assert_eq!(val.unwrap().len(), 1); assert_eq!(*val.unwrap().first().unwrap(), 42); let _val_mut = delayed_vec.get_value_mut(); - let value_owned = delayed_vec.take_inner().unwrap(); + let value_owned = delayed_vec.take_value().unwrap(); assert_eq!(*value_owned.first().unwrap(), 42); assert!(delayed_vec.is_uninitialized()); }); diff --git a/src/lib.rs b/src/lib.rs index f552ab8..752e902 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -43,7 +43,7 @@ pub trait DirectCacheAccess { /// returns a reference to the cache if applicable fn get_value(&self) -> Option<&T>; /// takes the value and leaves the promise in a valid state indicating its emptiness - fn take_inner(&mut self) -> Option; + fn take_value(&mut self) -> Option; } /// Blanket implementation for any `Option>` allows for better handling of option-laziness @@ -54,8 +54,8 @@ impl> DirectCacheAccess for Option fn get_value(&self) -> Option<&T> { self.as_ref().and_then(|inner| inner.get_value()) } - fn take_inner(&mut self) -> Option { - self.as_mut().and_then(|inner| inner.take_inner()) + fn take_value(&mut self) -> Option { + self.as_mut().and_then(|inner| inner.take_value()) } }