pub trait AnyVar:
Any
+ Send
+ Sync
+ Sealed {
Show 27 methods
// Required methods
fn clone_any(&self) -> BoxedAnyVar;
fn as_any(&self) -> &dyn Any;
fn as_unboxed_any(&self) -> &dyn Any;
fn double_boxed_any(self: Box<Self>) -> Box<dyn Any>;
fn var_type_id(&self) -> TypeId;
fn get_any(&self) -> Box<dyn AnyVarValue>;
fn with_any(&self, read: &mut dyn FnMut(&dyn AnyVarValue));
fn with_new_any(&self, read: &mut dyn FnMut(&dyn AnyVarValue)) -> bool;
fn set_any(
&self,
value: Box<dyn AnyVarValue>,
) -> Result<(), VarIsReadOnlyError>;
fn last_update(&self) -> VarUpdateId;
fn is_contextual(&self) -> bool;
fn capabilities(&self) -> VarCapability;
fn is_animating(&self) -> bool;
fn modify_importance(&self) -> usize;
fn hook_any(
&self,
pos_modify_action: Box<dyn Fn(&AnyVarHookArgs<'_>) -> bool + Send + Sync>,
) -> VarHandle;
fn hook_animation_stop(
&self,
handler: Box<dyn FnOnce() + Send>,
) -> Result<(), Box<dyn FnOnce() + Send>>;
fn strong_count(&self) -> usize;
fn weak_count(&self) -> usize;
fn actual_var_any(&self) -> BoxedAnyVar;
fn downgrade_any(&self) -> BoxedAnyWeakVar;
fn var_ptr(&self) -> VarPtr<'_>;
fn get_debug(&self) -> Txt;
fn update(&self) -> Result<(), VarIsReadOnlyError>;
fn map_debug(&self) -> BoxedVar<Txt>;
// Provided methods
fn is_new(&self) -> bool { ... }
fn perm(&self) { ... }
fn hold_any(&self, value: Box<dyn Any + Send + Sync>) -> VarHandle { ... }
}
Expand description
Required Methods§
sourcefn clone_any(&self) -> BoxedAnyVar
fn clone_any(&self) -> BoxedAnyVar
Clone the variable into a type erased box.
This is never BoxedVar<T>
, that is not a double box.
sourcefn as_unboxed_any(&self) -> &dyn Any
fn as_unboxed_any(&self) -> &dyn Any
Access to dyn Any
methods, on the underlying variable type if boxed.
sourcefn double_boxed_any(self: Box<Self>) -> Box<dyn Any>
fn double_boxed_any(self: Box<Self>) -> Box<dyn Any>
Access to Box<dyn Any>
methods, with the BoxedVar<T>
type.
This is a double-boxed to allow downcast to BoxedVar<T>
.
sourcefn var_type_id(&self) -> TypeId
fn var_type_id(&self) -> TypeId
Gets the TypeId
of T
in Var<T>
.
sourcefn get_any(&self) -> Box<dyn AnyVarValue>
fn get_any(&self) -> Box<dyn AnyVarValue>
Get a clone of the current value, with type erased.
sourcefn with_any(&self, read: &mut dyn FnMut(&dyn AnyVarValue))
fn with_any(&self, read: &mut dyn FnMut(&dyn AnyVarValue))
Visit the current value of the variable.
sourcefn with_new_any(&self, read: &mut dyn FnMut(&dyn AnyVarValue)) -> bool
fn with_new_any(&self, read: &mut dyn FnMut(&dyn AnyVarValue)) -> bool
Visit the current value of the variable, if it is_new
.
sourcefn set_any(&self, value: Box<dyn AnyVarValue>) -> Result<(), VarIsReadOnlyError>
fn set_any(&self, value: Box<dyn AnyVarValue>) -> Result<(), VarIsReadOnlyError>
Schedule a new value
for the variable, it will be set in the end of the current app update.
§Panics
Panics if the value
is not of the same var_type_id
.
sourcefn last_update(&self) -> VarUpdateId
fn last_update(&self) -> VarUpdateId
Last update ID a variable was modified, if the ID is equal to VARS.update_id
the variable is new.
sourcefn is_contextual(&self) -> bool
fn is_contextual(&self) -> bool
If the variable represents different values depending on the context where they are read.
sourcefn capabilities(&self) -> VarCapability
fn capabilities(&self) -> VarCapability
Flags that indicate what operations the variable is capable of in this update.
sourcefn is_animating(&self) -> bool
fn is_animating(&self) -> bool
If the variable current value was set by an active animation.
The variable is_new
when this changes to true
, but it may not be new when the value changes to false
.
If the variable is not updated at the last frame of the animation that has last set it, it will not update
just because that animation has ended. You can use hook_animation_stop
to get a notification when the
last animation stops, or use wait_animation
to get a future that is ready when is_animating
changes
from true
to false
.
sourcefn modify_importance(&self) -> usize
fn modify_importance(&self) -> usize
Gets a value that indicates the importance clearance that is needed to modify this variable.
If the variable has the MODIFY
capability, modify
requests will return Ok(())
, but they will be ignored
if the VARS.current_modify
importance is less than the variable’s at the moment the request is made.
Note that VARS.current_modify
outside animations always overrides this value, so direct modify requests
always override running animations.
This is the mechanism that ensures that only the latest animation has control of the variable value, most animations
check this value and automatically cancel if overridden, but event assigns from custom animations made using VARS.animate
are ignored if the variable is modified from a newer source then the animation.
If the variable does not have MODIFY
capability the value returned is undefined.
sourcefn 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
Setups a callback for just after the variable value update is applied, the closure runs in the root app context, just like
the 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.
The variable store a weak reference to the callback if it has the MODIFY
or CAPS_CHANGE
capabilities, otherwise
the callback is discarded and VarHandle::dummy
returned.
sourcefn 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>>
Register a handler
to be called when the current animation stops.
Note that the handler
is owned by the animation, not the variable, it will only be called/dropped when the
animation stops.
Returns the handler
as an error if the variable is not animating. Note that if you are interacting
with the variable from a non-UI thread the variable can stops animating between checking is_animating
and registering the hook, in this case the handler
will be returned as an error as well.
sourcefn strong_count(&self) -> usize
fn strong_count(&self) -> usize
Gets the number of strong references to the variable.
This is the Arc::strong_count
for Arc variables, the context var count for ContextVar<T>
, the boxed var count
for BoxedVar<T>
and 0
for LocalVar<T>
.
sourcefn weak_count(&self) -> usize
fn weak_count(&self) -> usize
Gets the number of weak references to the variable.
This is the Arc::weak_count
for Arc variables, the context var count for ContextVar<T>
, the boxed var count
for BoxedVar<T>
and 0
for LocalVar<T>
.
sourcefn actual_var_any(&self) -> BoxedAnyVar
fn actual_var_any(&self) -> BoxedAnyVar
Gets a clone of the represented var from ContextVar<T>
, gets a clone of self
for other var types.
sourcefn downgrade_any(&self) -> BoxedAnyWeakVar
fn downgrade_any(&self) -> BoxedAnyWeakVar
Create a weak reference to this Arc variable.
The weak reference is made to the actual_var
, if the actual var is a LocalVar<T>
a types::WeakArcVar<T>
is returned, for Arc vars an actual weak reference is made.
sourcefn var_ptr(&self) -> VarPtr<'_>
fn var_ptr(&self) -> VarPtr<'_>
Var pointer, that can be used to identify if two variables point to the same rc or context.
If two of these values are equal, both variables point to the same rc or context at the moment of comparison. Note that this is only for comparison, trying to access the variable internals is never safe.
sourcefn update(&self) -> Result<(), VarIsReadOnlyError>
fn update(&self) -> Result<(), VarIsReadOnlyError>
Schedule a variable update, even if the value does no change.
Usually variables only notify update if the value is changed to a different one, calling this method flags the variable to notify.
Provided Methods§
sourcefn is_new(&self) -> bool
fn is_new(&self) -> bool
Gets if the last_update
is the current update, meaning the variable value just changed.
Note that this is only reliable in threads synchronized with the UI update, this status can change at any time when called from other app threads.
Trait Implementations§
source§impl AnyVar for Box<dyn AnyVar>
impl AnyVar for Box<dyn AnyVar>
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 is_animating(&self) -> bool
fn is_animating(&self) -> bool
source§fn modify_importance(&self) -> usize
fn modify_importance(&self) -> usize
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.