Struct wnf::BorrowedState

source ·
pub struct BorrowedState<'a, T>where
    T: ?Sized,
{ /* private fields */ }
Expand description

A borrowed state

This has a lifetime parameter to tie it to something that owns the state, typically an OwnedState<T>.

Unlike OwnedState<T>, this implements Copy (and Clone) and does not delete the represented state on drop.

While borrowing in Rust usually refers to borrowing memory, this applies the idea of borrowing to an external entity, namely a state. It’s similar to BorrowedHandle<'_> in that regard.

Calling Clone::clone on a BorrowedState<'a, T> just makes a trivial copy, returning another BorrowedState<'a, T> with the same lifetime as the original one and representing the same underlying WNF state. The same applies to the ToOwned::to_owned method. If you want to turn a BorrowedState<'_, T> into an OwnedState<T> (which will then delete the underlying state on drop), use the BorrowedState::to_owned_state method.

The type parameter T is the type of data contained in the state.

Implementations§

Applies a transformation to the data of this state

See OwnedState::apply

Applies a fallible transformation to the data of this state

See OwnedState::try_apply

Applies a transformation to the data of this state as a box

See OwnedState::apply_boxed

Applies a fallible transformation to the data of this state as a box

See OwnedState::try_apply_boxed

Returns whether this state exists

See OwnedState::exists

Returns whether this state has at least one subscriber

See OwnedState::subscribers_present

Returns whether this state is “quiescent”, i.e. none of the listeners subscribed to it are currently running

See OwnedState::is_quiescent

Creates a BorrowedState<'static, T> with temporary lifetime and machine scope

This is a convenience method for quickly creating a state, e.g. for testing purposes. For more precise control over the created state, use the StateCreation builder.

Note that a newly created state is initialized with data of size zero. This means that unless the data type T is zero-sized or a slice type, you need to update the state data with a value of type T before querying it for the first time.

Errors

Returns an error if creating the state fails

Deletes this state

Returns an error if deleting the state fails

Queries the data of this state

See OwnedState::get

Queries the data of this state together with its change stamp

See OwnedState::query

Queries the data of this state as a box

See OwnedState::get_boxed

Queries the data of this state as a box together with its change stamp

See OwnedState::query_boxed

Queries the change stamp of this state

See OwnedState::change_stamp

Replaces the data of this state, returning the previous value

See OwnedState::replace

Replaces the data of this state, returning the previous value as a box

See OwnedState::replace_boxed

Returns the name of this state

Turns this BorrowedState<'_, T> into an OwnedState<T> representing the same underlying state

Note that the underlying state will be deleted when the OwnedState<T> is dropped.

Casts the data type of this state to a different type U

The returned BorrowedState<'a, U> represents the same underlying state, but treats it as containing data of a different type U.

Statically borrows the state with the given name

Note that an underlying state with the given name may or may not exist. The returned BorrowedState<'static, T> having a 'static lifetime just means that the state is borrowed directly from the system rather than from an OwnedState<T> that will be dropped at some point.

Statically borrows the state with the given name using the given type id

Note that an underlying state with the given name may or may not exist. The returned BorrowedState<'static, T> having a 'static lifetime just means that the state is borrowed directly from the system rather than from an OwnedState<T> that will be dropped at some point.

Updates the data of this state with the given value

See OwnedState::set

Updates the data of this state with the given value

See OwnedState::update

Available on crate feature subscribe only.

Subscribes the given state listener to this state

See OwnedState::subscribe

Available on crate feature wait_async only.

Waits until this state is updated

See OwnedState::wait_async

Available on crate feature wait_async only.

Waits until the data of this state satisfy a given predicate, returning the data

See OwnedState::wait_until_async

Available on crate feature wait_async only.

Waits until the data of this state satisfy a given predicate, returning the data as a box

See OwnedState::wait_until_boxed_async

Available on crate feature wait_blocking only.

Waits until this state is updated

See OwnedState::wait_blocking

Available on crate feature wait_blocking only.

Waits until the data of this state satisfy a given predicate, returning the data

See OwnedState::wait_until_blocking

Available on crate feature wait_blocking only.

Waits until the data of this state satisfy a given predicate, returning the data as a box

See OwnedState::wait_until_boxed_blocking

Trait Implementations§

The type of the data contained in the borrowed state
Borrows a value as a state
Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

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

Calls U::from(self).

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

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more