Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/immediatevalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -154,7 +154,7 @@ impl<T> DirectCacheAccess<T> for ImmediateValueState<T> {

/// 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<T> {
fn take_value(&mut self) -> Option<T> {
if matches!(self, ImmediateValueState::Success(_)) {
let val = mem::replace(self, ImmediateValueState::Empty);
return match val {
Expand All @@ -173,8 +173,8 @@ impl<T: Send + 'static> DirectCacheAccess<T> for ImmediateValuePromise<T> {
fn get_value(&self) -> Option<&T> {
self.state.get_value()
}
fn take_inner(&mut self) -> Option<T> {
self.state.take_inner()
fn take_value(&mut self) -> Option<T> {
self.state.take_value()
}
}

Expand Down Expand Up @@ -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));
}
Expand All @@ -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());
});
}
}
4 changes: 2 additions & 2 deletions src/lazyvalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl<T: Debug> DirectCacheAccess<T> for LazyValuePromise<T> {

/// 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<T> {
fn take_value(&mut self) -> Option<T> {
if self.state == DataState::UpToDate {
self.state = DataState::Uninitialized;
self.cache.take()
Expand Down Expand Up @@ -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());
});
Expand Down
4 changes: 2 additions & 2 deletions src/lazyvec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl<T: Debug> DirectCacheAccess<Vec<T>> for LazyVecPromise<T> {
/// 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<Vec<T>> {
fn take_value(&mut self) -> Option<Vec<T>> {
if self.state == DataState::UpToDate {
self.state = DataState::Uninitialized;
Some(mem::take(&mut self.data))
Expand Down Expand Up @@ -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());
});
Expand Down
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub trait DirectCacheAccess<T> {
/// 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<T>;
fn take_value(&mut self) -> Option<T>;
}

/// Blanket implementation for any `Option<DirectCacheAccess<T>>` allows for better handling of option-laziness
Expand All @@ -54,8 +54,8 @@ impl<T: Send + 'static, A: DirectCacheAccess<T>> DirectCacheAccess<T> for Option
fn get_value(&self) -> Option<&T> {
self.as_ref().and_then(|inner| inner.get_value())
}
fn take_inner(&mut self) -> Option<T> {
self.as_mut().and_then(|inner| inner.take_inner())
fn take_value(&mut self) -> Option<T> {
self.as_mut().and_then(|inner| inner.take_value())
}
}

Expand Down