Struct Owner
pub struct Owner {
pub(crate) inner: Arc<RwLock<OwnerInner>>,
pub(crate) shared_context: Option<Arc<dyn SharedContext + Send + Sync>>,
}Expand description
A reactive owner, which manages
- the cancellation of
Effects, - providing and accessing environment data via
provide_contextanduse_context, - running cleanup functions defined via
Owner::on_cleanup, and - an arena storage system to provide
Copyhandles viaArenaItem, which is what allows types likeRwSignal,Memo, and so on to beCopy.
Every effect and computed reactive value has an associated Owner. While it is running, this
is marked as the current Owner. Whenever it re-runs, this Owner is cleared by calling
Owner::with_cleanup. This runs cleanup functions, cancels any Effects created during the
last run, drops signals stored in the arena, and so on, because those effects and signals will
be re-created as needed during the next run.
When the owner is ultimately dropped, it will clean up its owned resources in the same way.
The โcurrent ownerโ is set on the thread-local basis: whenever one of these reactive nodes is
running, it will set the current owner on its thread with Owner::with or Owner::set,
allowing other reactive nodes implicitly to access the fact that it is currently the owner.
For a longer discussion of the ownership model, see here.
Fieldsยง
ยงinner: Arc<RwLock<OwnerInner>>hydration only.Implementationsยง
ยงimpl Owner
impl Owner
pub fn use_context_bidirectional<T>(&self) -> Option<T>where
T: Clone + 'static,
pub fn use_context_bidirectional<T>(&self) -> Option<T>where
T: Clone + 'static,
Searches for items stored in context in either direction, either among parents or among descendants.
ยงimpl Owner
impl Owner
pub fn debug_id(&self) -> usize
pub fn debug_id(&self) -> usize
Returns a unique identifier for this owner, which can be used to identify it for debugging purposes.
Intended for debugging only; this is not guaranteed to be stable between runs.
pub fn ancestry(&self) -> Vec<usize>
pub fn ancestry(&self) -> Vec<usize>
Returns the list of parents, grandparents, and ancestors, with values corresponding to
Owner::debug_id for each.
Intended for debugging only; this is not guaranteed to be stable between runs.
pub fn new() -> Owner
pub fn new() -> Owner
Creates a new Owner and registers it as a child of the current Owner, if there is one.
pub fn new_root(
shared_context: Option<Arc<dyn SharedContext + Send + Sync>>,
) -> Owner
Available on crate feature hydration only.
pub fn new_root( shared_context: Option<Arc<dyn SharedContext + Send + Sync>>, ) -> Owner
hydration only.Creates a new โrootโ context with the given [SharedContext], which allows sharing data
between the server and client.
Only one SharedContext needs to be created per request, and will be automatically shared
by any other Owners created under this one.
pub fn parent(&self) -> Option<Owner>
pub fn parent(&self) -> Option<Owner>
Returns the parent of this Owner, if any.
None when:
- This is a root owner
- The parent has been dropped
pub fn set(&self)
pub fn set(&self)
Sets this as the current Owner.
pub fn with<T>(&self, fun: impl FnOnce() -> T) -> T
pub fn with<T>(&self, fun: impl FnOnce() -> T) -> T
Runs the given function with this as the current Owner.
pub fn with_cleanup<T>(&self, fun: impl FnOnce() -> T) -> T
pub fn with_cleanup<T>(&self, fun: impl FnOnce() -> T) -> T
Cleans up this owner, the given function with this as the current Owner.
pub fn cleanup(&self)
pub fn cleanup(&self)
Cleans up this owner in the following order:
- Runs
cleanupon all children, - Runs all cleanup functions registered with
Owner::on_cleanup, - Drops the values of any arena-allocated
ArenaItems.
pub fn on_cleanup(fun: impl FnOnce() + Send + Sync + 'static)
pub fn on_cleanup(fun: impl FnOnce() + Send + Sync + 'static)
Registers a function to be run the next time the current owner is cleaned up.
Because the ownership model is associated with reactive nodes, each โdecision pointโ in an
application tends to have a separate Owner: as a result, these cleanup functions often
fill the same need as an โon unmountโ function in other UI approaches, etc.
Available on crate feature hydration only.
hydration only.Returns the [SharedContext] associated with this owner, if any.
pub fn unset(self)
pub fn unset(self)
Removes this from its state as the thread-local owner and drops it.
If there are other holders of this owner, it may not cleanup, if always cleaning up is required,
see Owner::unset_with_forced_cleanup.
pub fn unset_with_forced_cleanup(self)
pub fn unset_with_forced_cleanup(self)
Removes this from its state as the thread-local owner and drops it.
Unlike Owner::unset, this will always run cleanup on this owner,
even if there are other holders of this owner.
Available on crate feature hydration only.
hydration only.Returns the current [SharedContext], if any.
pub fn with_hydration<T>(fun: impl FnOnce() -> T + 'static) -> T
Available on crate feature hydration only.
pub fn with_hydration<T>(fun: impl FnOnce() -> T + 'static) -> T
hydration only.Runs the given function, after indicating that the current [SharedContext] should be
prepared to handle any data created in the function.
pub fn with_no_hydration<T>(fun: impl FnOnce() -> T + 'static) -> T
Available on crate feature hydration only.
pub fn with_no_hydration<T>(fun: impl FnOnce() -> T + 'static) -> T
hydration only.Runs the given function, after indicating that the current [SharedContext] should /// not handle data created in this function.
pub fn pause(&self)
pub fn pause(&self)
Pauses the execution of side effects for this owner, and any of its descendants.
If this owner is the owner for an Effect or RenderEffect, this effect will not run until Owner::resume is called. All children of this effects are also paused.
Any notifications will be ignored; effects that are notified will paused will not run when resumed, until they are notified again by a source after being resumed.
pub fn paused(&self) -> bool
pub fn paused(&self) -> bool
Whether this owner has been paused by Owner::pause.
pub fn resume(&self)
pub fn resume(&self)
Resumes side effects that have been paused by Owner::pause.
All children will also be resumed.
This will not cause side effects that were notified while paused to run, until they are notified again by a source after being resumed.
Trait Implementationsยง
Auto Trait Implementationsยง
impl Freeze for Owner
impl !RefUnwindSafe for Owner
impl Send for Owner
impl Sync for Owner
impl Unpin for Owner
impl !UnwindSafe for Owner
Blanket Implementationsยง
Sourceยงimpl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for Swhere
T: Real + Zero + Arithmetics + Clone,
Swp: WhitePoint<T>,
Dwp: WhitePoint<T>,
D: AdaptFrom<S, Swp, Dwp, T>,
impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for Swhere
T: Real + Zero + Arithmetics + Clone,
Swp: WhitePoint<T>,
Dwp: WhitePoint<T>,
D: AdaptFrom<S, Swp, Dwp, T>,
Sourceยงfn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<T>,
fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<T>,
Sourceยงfn adapt_into(self) -> D
fn adapt_into(self) -> D
Sourceยงimpl<T, C> ArraysFrom<C> for Twhere
C: IntoArrays<T>,
impl<T, C> ArraysFrom<C> for Twhere
C: IntoArrays<T>,
Sourceยงfn arrays_from(colors: C) -> T
fn arrays_from(colors: C) -> T
Sourceยงimpl<T, C> ArraysInto<C> for Twhere
C: FromArrays<T>,
impl<T, C> ArraysInto<C> for Twhere
C: FromArrays<T>,
Sourceยงfn arrays_into(self) -> C
fn arrays_into(self) -> C
Sourceยงimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Sourceยงfn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Sourceยงimpl<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for Uwhere
T: FromCam16Unclamped<WpParam, U>,
impl<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for Uwhere
T: FromCam16Unclamped<WpParam, U>,
Sourceยงtype Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar
type Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar
parameters when converting.Sourceยงfn cam16_into_unclamped(
self,
parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar>,
) -> T
fn cam16_into_unclamped( self, parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar>, ) -> T
self into C, using the provided parameters.Sourceยงimpl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Sourceยงimpl<T, C> ComponentsFrom<C> for Twhere
C: IntoComponents<T>,
impl<T, C> ComponentsFrom<C> for Twhere
C: IntoComponents<T>,
Sourceยงfn components_from(colors: C) -> T
fn components_from(colors: C) -> T
ยงimpl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
ยงfn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.ยงfn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.ยงfn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Anyโs vtable from &Traitโs.ยงfn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Anyโs vtable from &mut Traitโs.ยงimpl<T> DowncastSend for T
impl<T> DowncastSend for T
ยงimpl<T> DowncastSync for T
impl<T> DowncastSync for T
Sourceยงimpl<T> FromAngle<T> for T
impl<T> FromAngle<T> for T
Sourceยงfn from_angle(angle: T) -> T
fn from_angle(angle: T) -> T
angle.Sourceยงimpl<T, U> FromStimulus<U> for Twhere
U: IntoStimulus<T>,
impl<T, U> FromStimulus<U> for Twhere
U: IntoStimulus<T>,
Sourceยงfn from_stimulus(other: U) -> T
fn from_stimulus(other: U) -> T
other into Self, while performing the appropriate scaling,
rounding and clamping.ยงimpl<T> Instrument for T
impl<T> Instrument for T
ยงfn instrument(self, span: Span) -> Instrumented<Self> โ
fn instrument(self, span: Span) -> Instrumented<Self> โ
Sourceยงimpl<T, U> IntoAngle<U> for Twhere
U: FromAngle<T>,
impl<T, U> IntoAngle<U> for Twhere
U: FromAngle<T>,
Sourceยงfn into_angle(self) -> U
fn into_angle(self) -> U
T.Sourceยงimpl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for Uwhere
T: Cam16FromUnclamped<WpParam, U>,
impl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for Uwhere
T: Cam16FromUnclamped<WpParam, U>,
Sourceยงtype Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar
type Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar
parameters when converting.Sourceยงfn into_cam16_unclamped(
self,
parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar>,
) -> T
fn into_cam16_unclamped( self, parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar>, ) -> T
self into C, using the provided parameters.Sourceยงimpl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
impl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
Sourceยงfn into_color(self) -> U
fn into_color(self) -> U
Sourceยงimpl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
impl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
Sourceยงfn into_color_unclamped(self) -> U
fn into_color_unclamped(self) -> U
Sourceยงimpl<T> IntoEither for T
impl<T> IntoEither for T
Sourceยงfn into_either(self, into_left: bool) -> Either<Self, Self> โ
fn into_either(self, into_left: bool) -> Either<Self, Self> โ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSourceยงfn into_either_with<F>(self, into_left: F) -> Either<Self, Self> โ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> โ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreยงimpl<T, I> IntoReactiveValue<T, __IntoReactiveValueMarkerBaseCase> for Iwhere
I: Into<T>,
impl<T, I> IntoReactiveValue<T, __IntoReactiveValueMarkerBaseCase> for Iwhere
I: Into<T>,
ยงfn into_reactive_value(self) -> T
fn into_reactive_value(self) -> T
self into a T.Sourceยงimpl<T> IntoStimulus<T> for T
impl<T> IntoStimulus<T> for T
Sourceยงfn into_stimulus(self) -> T
fn into_stimulus(self) -> T
self into T, while performing the appropriate scaling,
rounding and clamping.ยงimpl<T> Pointable for T
impl<T> Pointable for T
ยงimpl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
ยงimpl<T> SerializableKey for T
impl<T> SerializableKey for T
ยงimpl<T> StorageAccess<T> for T
impl<T> StorageAccess<T> for T
ยงfn as_borrowed(&self) -> &T
fn as_borrowed(&self) -> &T
ยงfn into_taken(self) -> T
fn into_taken(self) -> T
Sourceยงimpl<T, C> TryComponentsInto<C> for Twhere
C: TryFromComponents<T>,
impl<T, C> TryComponentsInto<C> for Twhere
C: TryFromComponents<T>,
Sourceยงtype Error = <C as TryFromComponents<T>>::Error
type Error = <C as TryFromComponents<T>>::Error
try_into_colors fails to cast.Sourceยงfn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>
fn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>
Sourceยงimpl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
impl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
Sourceยงfn try_into_color(self) -> Result<U, OutOfBounds<U>>
fn try_into_color(self) -> Result<U, OutOfBounds<U>>
OutOfBounds error is returned which contains
the unclamped color. Read more