Struct zng_var::ContextVar
source · pub struct ContextVar<T: VarValue>(/* private fields */);
Expand description
Represents another variable in a context.
Context variables are Var<T>
implementers that represent a contextual value, unlike other variables it does not own
the value it represents.
See context_var!
for more details.
Implementations§
source§impl<T: VarValue> ContextVar<T>
impl<T: VarValue> ContextVar<T>
sourcepub fn with_context<R>(
self,
id: ContextInitHandle,
var: &mut Option<Arc<BoxedVar<T>>>,
action: impl FnOnce() -> R,
) -> R
pub fn with_context<R>( self, id: ContextInitHandle, var: &mut Option<Arc<BoxedVar<T>>>, action: impl FnOnce() -> R, ) -> R
Runs action
with this context var representing the other var
in the current thread.
The var
must be Some
and must be the actual_var
, it is moved to the context storage during the call.
Note that the var
must be the same for subsequent calls in the same context, otherwise contextualized
variables may not update their binding, in widgets you must re-init the descendants if you replace the var
.
sourcepub fn with_context_var<R>(
self,
id: ContextInitHandle,
var: impl IntoVar<T>,
action: impl FnOnce() -> R,
) -> R
pub fn with_context_var<R>( self, id: ContextInitHandle, var: impl IntoVar<T>, action: impl FnOnce() -> R, ) -> R
Runs action
with this context var representing the other var
in the current thread.
Note that the var
must be the same for subsequent calls in the same context, otherwise contextualized
variables may not update their binding, in widgets you must re-init the descendants if you replace the var
.
The var
is converted into var, the actual var, boxed and placed in a new Arc
, you can use the with_context
method to avoid doing this in a hot path.
Trait Implementations§
source§impl<T: VarValue> AnyVar for ContextVar<T>
impl<T: VarValue> AnyVar for ContextVar<T>
source§fn clone_any(&self) -> BoxedAnyVar
fn clone_any(&self) -> BoxedAnyVar
source§fn as_unboxed_any(&self) -> &dyn Any
fn as_unboxed_any(&self) -> &dyn Any
dyn Any
methods, on the underlying variable type if boxed.source§fn var_type_id(&self) -> TypeId
fn var_type_id(&self) -> TypeId
source§fn get_any(&self) -> Box<dyn AnyVarValue>
fn get_any(&self) -> Box<dyn AnyVarValue>
source§fn with_any(&self, read: &mut dyn FnMut(&dyn AnyVarValue))
fn with_any(&self, read: &mut dyn FnMut(&dyn AnyVarValue))
source§fn with_new_any(&self, read: &mut dyn FnMut(&dyn AnyVarValue)) -> bool
fn with_new_any(&self, read: &mut dyn FnMut(&dyn AnyVarValue)) -> bool
is_new
.source§fn set_any(&self, value: Box<dyn AnyVarValue>) -> Result<(), VarIsReadOnlyError>
fn set_any(&self, value: Box<dyn AnyVarValue>) -> Result<(), VarIsReadOnlyError>
value
for the variable, it will be set in the end of the current app update. Read moresource§fn last_update(&self) -> VarUpdateId
fn last_update(&self) -> VarUpdateId
VARS.update_id
the variable is new.source§fn is_contextual(&self) -> bool
fn is_contextual(&self) -> bool
source§fn capabilities(&self) -> VarCapability
fn capabilities(&self) -> VarCapability
source§fn hook_any(
&self,
pos_modify_action: Box<dyn Fn(&AnyVarHookArgs<'_>) -> bool + Send + Sync>,
) -> VarHandle
fn hook_any( &self, pos_modify_action: Box<dyn Fn(&AnyVarHookArgs<'_>) -> bool + Send + Sync>, ) -> VarHandle
modify
closure. The closure can return if it is retained after each call. If you modify another variable in a
hook the modification applies in the same update, variable mapping and binding is implemented using hooks. Read moresource§fn hook_animation_stop(
&self,
handler: Box<dyn FnOnce() + Send>,
) -> Result<(), Box<dyn FnOnce() + Send>>
fn hook_animation_stop( &self, handler: Box<dyn FnOnce() + Send>, ) -> Result<(), Box<dyn FnOnce() + Send>>
handler
to be called when the current animation stops. Read moresource§fn strong_count(&self) -> usize
fn strong_count(&self) -> usize
source§fn weak_count(&self) -> usize
fn weak_count(&self) -> usize
source§fn actual_var_any(&self) -> BoxedAnyVar
fn actual_var_any(&self) -> BoxedAnyVar
ContextVar<T>
, gets a clone of self
for other var types.source§fn downgrade_any(&self) -> BoxedAnyWeakVar
fn downgrade_any(&self) -> BoxedAnyWeakVar
source§fn is_animating(&self) -> bool
fn is_animating(&self) -> bool
source§fn modify_importance(&self) -> usize
fn modify_importance(&self) -> usize
source§fn var_ptr(&self) -> VarPtr<'_>
fn var_ptr(&self) -> VarPtr<'_>
source§fn update(&self) -> Result<(), VarIsReadOnlyError>
fn update(&self) -> Result<(), VarIsReadOnlyError>
source§impl<T: Clone + VarValue> Clone for ContextVar<T>
impl<T: Clone + VarValue> Clone for ContextVar<T>
source§fn clone(&self) -> ContextVar<T>
fn clone(&self) -> ContextVar<T>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<T: VarValue> ContextLocalKeyProvider for ContextVar<T>
impl<T: VarValue> ContextLocalKeyProvider for ContextVar<T>
source§fn context_local_key(&'static self) -> AppLocalId
fn context_local_key(&'static self) -> AppLocalId
source§impl<T: VarValue> IntoVar<T> for ContextVar<T>
impl<T: VarValue> IntoVar<T> for ContextVar<T>
source§impl<T: VarValue> Var<T> for ContextVar<T>
impl<T: VarValue> Var<T> for ContextVar<T>
source§type ReadOnly = ReadOnlyVar<T, ContextVar<T>>
type ReadOnly = ReadOnlyVar<T, ContextVar<T>>
Var::read_only
.source§type ActualVar = Box<dyn VarBoxed<T>>
type ActualVar = Box<dyn VarBoxed<T>>
Var::actual_var
.source§type Downgrade = Box<dyn WeakVarBoxed<T>>
type Downgrade = Box<dyn WeakVarBoxed<T>>
Var::downgrade
.source§type MapBidi<O: VarValue> = ContextualizedVar<O>
type MapBidi<O: VarValue> = ContextualizedVar<O>
Var::map_bidi
.source§type FlatMap<O: VarValue, V: Var<O>> = ContextualizedVar<O>
type FlatMap<O: VarValue, V: Var<O>> = ContextualizedVar<O>
Var::flat_map
.source§type FilterMap<O: VarValue> = ContextualizedVar<O>
type FilterMap<O: VarValue> = ContextualizedVar<O>
Var::filter_map
.source§type FilterMapBidi<O: VarValue> = ContextualizedVar<O>
type FilterMapBidi<O: VarValue> = ContextualizedVar<O>
Var::filter_map_bidi
.source§type MapRef<O: VarValue> = MapRef<T, O, ContextVar<T>>
type MapRef<O: VarValue> = MapRef<T, O, ContextVar<T>>
Var::map_ref
.source§type MapRefBidi<O: VarValue> = MapRefBidi<T, O, ContextVar<T>>
type MapRefBidi<O: VarValue> = MapRefBidi<T, O, ContextVar<T>>
Var::map_ref_bidi
.source§type Easing = ContextualizedVar<T>
type Easing = ContextualizedVar<T>
Var::easing
.source§fn modify<F>(&self, modify: F) -> Result<(), VarIsReadOnlyError>
fn modify<F>(&self, modify: F) -> Result<(), VarIsReadOnlyError>
source§fn actual_var(self) -> BoxedVar<T>
fn actual_var(self) -> BoxedVar<T>
source§fn downgrade(&self) -> BoxedWeakVar<T>
fn downgrade(&self) -> BoxedWeakVar<T>
source§fn into_value(self) -> T
fn into_value(self) -> T
source§fn read_only(&self) -> Self::ReadOnly
fn read_only(&self) -> Self::ReadOnly
source§fn map<O, M>(&self, map: M) -> Self::Map<O>
fn map<O, M>(&self, map: M) -> Self::Map<O>
source§fn map_bidi<O, M, B>(&self, map: M, map_back: B) -> Self::MapBidi<O>
fn map_bidi<O, M, B>(&self, map: M, map_back: B) -> Self::MapBidi<O>
source§fn flat_map<O, V, M>(&self, map: M) -> Self::FlatMap<O, V>
fn flat_map<O, V, M>(&self, map: M) -> Self::FlatMap<O, V>
source§fn filter_map<O, M, I>(&self, map: M, fallback: I) -> Self::FilterMap<O>
fn filter_map<O, M, I>(&self, map: M, fallback: I) -> Self::FilterMap<O>
source§fn filter_map_bidi<O, M, B, I>(
&self,
map: M,
map_back: B,
fallback: I,
) -> Self::FilterMapBidi<O>
fn filter_map_bidi<O, M, B, I>( &self, map: M, map_back: B, fallback: I, ) -> Self::FilterMapBidi<O>
source§fn map_ref<O, M>(&self, map: M) -> Self::MapRef<O>
fn map_ref<O, M>(&self, map: M) -> Self::MapRef<O>
self
. The map
closure is called for each value access, it must reference the
value O
that already exists in T
.source§fn map_ref_bidi<O, M, B>(&self, map: M, map_mut: B) -> Self::MapRefBidi<O>
fn map_ref_bidi<O, M, B>(&self, map: M, map_mut: B) -> Self::MapRefBidi<O>
self
. The map
closure is called for each value access, it must reference the
value O
that already exists in T
, the map_mut
closure is called for every modify request, it must do the same
as map
but with mutable access.source§fn easing_with<F, S>(
&self,
duration: Duration,
easing: F,
sampler: S,
) -> Self::Easingwhere
T: Transitionable,
F: Fn(EasingTime) -> EasingStep + Send + Sync + 'static,
S: Fn(&Transition<T>, EasingStep) -> T + Send + Sync + 'static,
fn easing_with<F, S>(
&self,
duration: Duration,
easing: F,
sampler: S,
) -> Self::Easingwhere
T: Transitionable,
F: Fn(EasingTime) -> EasingStep + Send + Sync + 'static,
S: Fn(&Transition<T>, EasingStep) -> T + Send + Sync + 'static,
source§fn boxed(self) -> BoxedVar<T>where
Self: Sized,
fn boxed(self) -> BoxedVar<T>where
Self: Sized,
BoxedVar<T>
, does not double box.source§fn boxed_any(self) -> BoxedAnyVarwhere
Self: Sized,
fn boxed_any(self) -> BoxedAnyVarwhere
Self: Sized,
BoxedAnyVar
, does not double box.source§fn hook(
&self,
pos_modify_action: impl Fn(&VarHookArgs<'_, T>) -> bool + Send + Sync + 'static,
) -> VarHandle
fn hook( &self, pos_modify_action: impl Fn(&VarHookArgs<'_, T>) -> bool + Send + Sync + 'static, ) -> VarHandle
modify
closure. The closure can return if it is retained after each call. If you modify another variable in a
hook the modification applies in the same update, variable mapping and binding is implemented using hooks. Read moresource§fn wait_update(&self) -> impl Future<Output = VarUpdateId> + Send + Sync
fn wait_update(&self) -> impl Future<Output = VarUpdateId> + Send + Sync
last_update
to change. Read moresource§fn wait_value(
&self,
predicate: impl Fn(&T) -> bool + Send + Sync,
) -> impl Future<Output = ()> + Send + Sync
fn wait_value( &self, predicate: impl Fn(&T) -> bool + Send + Sync, ) -> impl Future<Output = ()> + Send + Sync
predicate
.source§fn with_new<R, F>(&self, read: F) -> Option<R>
fn with_new<R, F>(&self, read: F) -> Option<R>
is_new
.source§fn get_ne(&self, value: &mut T) -> bool
fn get_ne(&self, value: &mut T) -> bool
value
if the current value is not equal to it.source§fn get_new_into(&self, value: &mut T) -> bool
fn get_new_into(&self, value: &mut T) -> bool
value
if the current value is_new
.source§fn get_new_ne(&self, value: &mut T) -> bool
fn get_new_ne(&self, value: &mut T) -> bool
value
if the variable value is_new
and not equal to the value
.source§fn set<I>(&self, value: I) -> Result<(), VarIsReadOnlyError>where
I: Into<T>,
fn set<I>(&self, value: I) -> Result<(), VarIsReadOnlyError>where
I: Into<T>,
value
for the variable, it will be set in the end of the current app update.source§fn set_from<I>(&self, other: &I) -> Result<(), VarIsReadOnlyError>where
I: Var<T>,
fn set_from<I>(&self, other: &I) -> Result<(), VarIsReadOnlyError>where
I: Var<T>,
value
for the variable, it will be set in the end of the current app update to the updated
value of other
, so if the other var has already scheduled an update, the updated value will be used. Read moresource§fn set_from_map<Iv, I, M>(
&self,
other: &I,
map: M,
) -> Result<(), VarIsReadOnlyError>
fn set_from_map<Iv, I, M>( &self, other: &I, map: M, ) -> Result<(), VarIsReadOnlyError>
other
value at the time of update, mapped to the type of self
.source§fn filter_try_into<O, I>(&self, fallback: I) -> Self::FilterMap<O>
fn filter_try_into<O, I>(&self, fallback: I) -> Self::FilterMap<O>
source§fn bind_filter_map<T2, V2, F>(&self, other: &V2, map: F) -> VarHandle
fn bind_filter_map<T2, V2, F>(&self, other: &V2, map: F) -> VarHandle
other
with the new values of self
transformed by map
, if the closure returns a value. Read moresource§fn bind_map_bidi<T2, V2, M, B>(
&self,
other: &V2,
map: M,
map_back: B,
) -> VarHandles
fn bind_map_bidi<T2, V2, M, B>( &self, other: &V2, map: M, map_back: B, ) -> VarHandles
source§fn bind_filter_map_bidi<T2, V2, M, B>(
&self,
other: &V2,
map: M,
map_back: B,
) -> VarHandles
fn bind_filter_map_bidi<T2, V2, M, B>( &self, other: &V2, map: M, map_back: B, ) -> VarHandles
self
to other
and back with the new values of self
transformed by map
and the new values of other
transformed
by map_back
, the value is assigned in a update only if the closures returns a value. Read moresource§fn set_bind<V2>(&self, other: &V2) -> VarHandlewhere
V2: Var<T>,
fn set_bind<V2>(&self, other: &V2) -> VarHandlewhere
V2: Var<T>,
other.set_from(self)
and self.bind(other)
.source§fn bind_bidi<V2>(&self, other: &V2) -> VarHandleswhere
V2: Var<T>,
fn bind_bidi<V2>(&self, other: &V2) -> VarHandleswhere
V2: Var<T>,
other
with the new values of self
and self
with the new values of other
. Read moresource§fn trace_value<E, S>(&self, enter_value: E) -> VarHandle
fn trace_value<E, S>(&self, enter_value: E) -> VarHandle
source§fn animate<A>(&self, animate: A) -> AnimationHandle
fn animate<A>(&self, animate: A) -> AnimationHandle
source§fn sequence<A>(&self, animate: A) -> VarHandle
fn sequence<A>(&self, animate: A) -> VarHandle
animate
, the closure is called once at the start to begin, then again every time
the variable stops animating. Read moresource§fn step_oci<N>(&self, new_value: N, delay: Duration) -> AnimationHandlewhere
N: Into<T>,
fn step_oci<N>(&self, new_value: N, delay: Duration) -> AnimationHandlewhere
N: Into<T>,
new_value
, every time the delay
elapses the variable is set to the next value.source§fn set_step_oci<V0, V1>(
&self,
from: V0,
to: V1,
delay: Duration,
) -> AnimationHandle
fn set_step_oci<V0, V1>( &self, from: V0, to: V1, delay: Duration, ) -> AnimationHandle
from
and to
, the variable is set to from
to start and every time the delay
elapses
the variable is set to the next value.source§fn steps<F>(
&self,
steps: Vec<(Factor, T)>,
duration: Duration,
easing: F,
) -> AnimationHandle
fn steps<F>( &self, steps: Vec<(Factor, T)>, duration: Duration, easing: F, ) -> AnimationHandle
duration
elapses. Read moresource§fn debug(&self) -> VarDebug<'_, T, Self>
fn debug(&self) -> VarDebug<'_, T, Self>
fmt::Debug
to write the var value.impl<T: VarValue> Copy for ContextVar<T>
Auto Trait Implementations§
impl<T> Freeze for ContextVar<T>
impl<T> RefUnwindSafe for ContextVar<T>
impl<T> Send for ContextVar<T>
impl<T> Sync for ContextVar<T>
impl<T> Unpin for ContextVar<T>
impl<T> UnwindSafe for ContextVar<T>
Blanket Implementations§
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<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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