pub struct CopyValue<T: 'static> { /* private fields */ }
Expand description

CopyValue is a wrapper around a value to make the value mutable and Copy.

It is internally backed by generational_box::GenerationalBox.

Implementations§

source§

impl<T: 'static> CopyValue<T>

source

pub fn new(value: T) -> Self

Create a new CopyValue. The value will be stored in the current component.

Once the component this value is created in is dropped, the value will be dropped.

source

pub fn new_in_scope(value: T, scope: ScopeId) -> Self

Create a new CopyValue. The value will be stored in the given scope. When the specified scope is dropped, the value will be dropped.

source

pub fn origin_scope(&self) -> ScopeId

Get the scope this value was created in.

source

pub fn try_read(&self) -> Option<Ref<'_, T>>

Try to read the value. If the value has been dropped, this will return None.

source

pub fn read(&self) -> Ref<'static, T>

Read the value. If the value has been dropped, this will panic.

source

pub fn try_write(&self) -> Option<RefMut<'static, T>>

Try to write the value. If the value has been dropped, this will return None.

source

pub fn write(&self) -> RefMut<'static, T>

Write the value. If the value has been dropped, this will panic.

source

pub fn set(&mut self, value: T)

Set the value. If the value has been dropped, this will panic.

source

pub fn with<O>(&self, f: impl FnOnce(&T) -> O) -> O

Run a function with a reference to the value. If the value has been dropped, this will panic.

source

pub fn with_mut<O>(&self, f: impl FnOnce(&mut T) -> O) -> O

Run a function with a mutable reference to the value. If the value has been dropped, this will panic.

source§

impl<T: Clone + 'static> CopyValue<T>

source

pub fn value(&self) -> T

Get the value. If the value has been dropped, this will panic.

source§

impl<T: 'static> CopyValue<Vec<T>>

source

pub fn get(&self, index: usize) -> Option<Ref<'_, T>>

Read a value from the inner vector.

source§

impl<T: 'static> CopyValue<Option<T>>

source

pub fn unwrap(&self) -> Twhere T: Clone,

Unwraps the inner value and clones it.

source

pub fn as_ref(&self) -> Option<Ref<'_, T>>

Attemps to read the inner value of the Option.

source§

impl<T: 'static> CopyValue<Vec<T>>

source

pub fn push(&self, value: T)

Pushes a new value to the end of the vector.

source

pub fn pop(&self) -> Option<T>

Pops the last value from the vector.

source

pub fn insert(&self, index: usize, value: T)

Inserts a new value at the given index.

source

pub fn remove(&self, index: usize) -> T

Removes the value at the given index.

source

pub fn clear(&self)

Clears the vector, removing all values.

source

pub fn extend(&self, iter: impl IntoIterator<Item = T>)

Extends the vector with the given iterator.

source

pub fn truncate(&self, len: usize)

Truncates the vector to the given length.

source

pub fn swap_remove(&self, index: usize) -> T

Swaps two values in the vector.

source

pub fn retain(&self, f: impl FnMut(&T) -> bool)

Retains only the values that match the given predicate.

source

pub fn split_off(&self, at: usize) -> Vec<T>

Splits the vector into two at the given index.

source§

impl<T: 'static> CopyValue<Option<T>>

source

pub fn take(&self) -> Option<T>

Takes the value out of the Option.

source

pub fn replace(&self, value: T) -> Option<T>

Replace the value in the Option.

source

pub fn get_or_insert(&self, default: T) -> Ref<'_, T>

Gets the value out of the Option, or inserts the given value if the Option is empty.

source

pub fn get_or_insert_with(&self, default: impl FnOnce() -> T) -> Ref<'_, T>

Gets the value out of the Option, or inserts the value returned by the given function if the Option is empty.

source§

impl<T: 'static> CopyValue<Vec<T>>

source

pub fn get_mut(&self, index: usize) -> Option<RefMut<'_, T>>

Write to an element in the inner vector.

source§

impl<T: 'static> CopyValue<Option<T>>

source

pub fn as_mut(&self) -> Option<RefMut<'_, T>>

Deref the inner value mutably.

Trait Implementations§

source§

impl<T: Add<Output = T> + Copy + 'static> Add<T> for CopyValue<T>

§

type Output = T

The resulting type after applying the + operator.
source§

fn add(self, rhs: T) -> Self::Output

Performs the + operation. Read more
source§

impl<T: Add<Output = T> + Copy + 'static> AddAssign<T> for CopyValue<T>

source§

fn add_assign(&mut self, rhs: T)

Performs the += operation. Read more
source§

impl<T> Clone for CopyValue<T>

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T: Debug + 'static> Debug for CopyValue<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T: Default + 'static> Default for CopyValue<T>

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<T> Deref for CopyValue<T>

§

type Target = dyn Fn() -> Ref<'static, T>

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl<T: Display + 'static> Display for CopyValue<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T: Div<Output = T> + Copy + 'static> Div<T> for CopyValue<T>

§

type Output = T

The resulting type after applying the / operator.
source§

fn div(self, rhs: T) -> Self::Output

Performs the / operation. Read more
source§

impl<T: Div<Output = T> + Copy + 'static> DivAssign<T> for CopyValue<T>

source§

fn div_assign(&mut self, rhs: T)

Performs the /= operation. Read more
source§

impl<T: Clone + 'static> IntoIterator for CopyValue<Vec<T>>

§

type IntoIter = CopyValueIterator<T>

Which kind of iterator are we turning this into?
§

type Item = T

The type of the elements being iterated over.
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<T: Mul<Output = T> + Copy + 'static> Mul<T> for CopyValue<T>

§

type Output = T

The resulting type after applying the * operator.
source§

fn mul(self, rhs: T) -> Self::Output

Performs the * operation. Read more
source§

impl<T: Mul<Output = T> + Copy + 'static> MulAssign<T> for CopyValue<T>

source§

fn mul_assign(&mut self, rhs: T)

Performs the *= operation. Read more
source§

impl<T: 'static> PartialEq<CopyValue<T>> for CopyValue<T>

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T: Sub<Output = T> + Copy + 'static> Sub<T> for CopyValue<T>

§

type Output = T

The resulting type after applying the - operator.
source§

fn sub(self, rhs: T) -> Self::Output

Performs the - operation. Read more
source§

impl<T: Sub<Output = T> + Copy + 'static> SubAssign<T> for CopyValue<T>

source§

fn sub_assign(&mut self, rhs: T)

Performs the -= operation. Read more
source§

impl<T> Copy for CopyValue<T>

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for CopyValue<T>

§

impl<T> !Send for CopyValue<T>

§

impl<T> !Sync for CopyValue<T>

§

impl<T> Unpin for CopyValue<T>where T: Unpin,

§

impl<T> !UnwindSafe for CopyValue<T>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<T> Dep for Twhere T: 'static + PartialEq<T> + Clone,