zng_var

Trait AnyVar

source
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

Methods of Var<T> that are object safe.

This trait is sealed and cannot be implemented for types outside of this crate.

Required Methods§

source

fn clone_any(&self) -> BoxedAnyVar

Clone the variable into a type erased box.

This is never BoxedVar<T>, that is not a double box.

source

fn as_any(&self) -> &dyn Any

Access to dyn Any methods.

source

fn as_unboxed_any(&self) -> &dyn Any

Access to dyn Any methods, on the underlying variable type if boxed.

source

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>.

source

fn var_type_id(&self) -> TypeId

Gets the TypeId of T in Var<T>.

source

fn get_any(&self) -> Box<dyn AnyVarValue>

Get a clone of the current value, with type erased.

source

fn with_any(&self, read: &mut dyn FnMut(&dyn AnyVarValue))

Visit the current value of the variable.

source

fn with_new_any(&self, read: &mut dyn FnMut(&dyn AnyVarValue)) -> bool

Visit the current value of the variable, if it is_new.

source

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.

source

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.

source

fn is_contextual(&self) -> bool

If the variable represents different values depending on the context where they are read.

source

fn capabilities(&self) -> VarCapability

Flags that indicate what operations the variable is capable of in this update.

source

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.

source

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.

source

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.

source

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.

source

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>.

source

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>.

source

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.

source

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.

source

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.

source

fn get_debug(&self) -> Txt

Get the value as a debug Txt.

source

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.

source

fn map_debug(&self) -> BoxedVar<Txt>

Create a map that converts from T to a Txt debug print.

Provided Methods§

source

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.

source

fn perm(&self)

Hold the variable in memory until the app exit.

source

fn hold_any(&self, value: Box<dyn Any + Send + Sync>) -> VarHandle

Keep other alive until the handle or self are dropped.

Trait Implementations§

source§

impl AnyVar for Box<dyn AnyVar>

source§

fn clone_any(&self) -> BoxedAnyVar

Clone the variable into a type erased box. Read more
source§

fn as_any(&self) -> &dyn Any

Access to dyn Any methods.
source§

fn as_unboxed_any(&self) -> &dyn Any

Access to dyn Any methods, on the underlying variable type if boxed.
source§

fn double_boxed_any(self: Box<Self>) -> Box<dyn Any>

Access to Box<dyn Any> methods, with the BoxedVar<T> type. Read more
source§

fn var_type_id(&self) -> TypeId

Gets the TypeId of T in Var<T>.
source§

fn get_any(&self) -> Box<dyn AnyVarValue>

Get a clone of the current value, with type erased.
source§

fn with_any(&self, read: &mut dyn FnMut(&dyn AnyVarValue))

Visit the current value of the variable.
source§

fn with_new_any(&self, read: &mut dyn FnMut(&dyn AnyVarValue)) -> bool

Visit the current value of the variable, if it is_new.
source§

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. Read more
source§

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.
source§

fn is_contextual(&self) -> bool

If the variable represents different values depending on the context where they are read.
source§

fn capabilities(&self) -> VarCapability

Flags that indicate what operations the variable is capable of in this update.
source§

fn is_animating(&self) -> bool

If the variable current value was set by an active animation. Read more
source§

fn modify_importance(&self) -> usize

Gets a value that indicates the importance clearance that is needed to modify this variable. Read more
source§

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. Read more
source§

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. Read more
source§

fn strong_count(&self) -> usize

Gets the number of strong references to the variable. Read more
source§

fn weak_count(&self) -> usize

Gets the number of weak references to the variable. Read more
source§

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.
source§

fn downgrade_any(&self) -> BoxedAnyWeakVar

Create a weak reference to this Arc variable. Read more
source§

fn var_ptr(&self) -> VarPtr<'_>

Var pointer, that can be used to identify if two variables point to the same rc or context. Read more
source§

fn get_debug(&self) -> Txt

Get the value as a debug Txt.
source§

fn update(&self) -> Result<(), VarIsReadOnlyError>

Schedule a variable update, even if the value does no change. Read more
source§

fn map_debug(&self) -> BoxedVar<Txt>

Create a map that converts from T to a Txt debug print.
source§

fn is_new(&self) -> bool

Gets if the last_update is the current update, meaning the variable value just changed. Read more
source§

fn perm(&self)

Hold the variable in memory until the app exit.
source§

fn hold_any(&self, value: Box<dyn Any + Send + Sync>) -> VarHandle

Keep other alive until the handle or self are dropped.

Implementations on Foreign Types§

source§

impl AnyVar for Box<dyn AnyVar>

source§

fn clone_any(&self) -> BoxedAnyVar

source§

fn as_any(&self) -> &dyn Any

source§

fn as_unboxed_any(&self) -> &dyn Any

source§

fn double_boxed_any(self: Box<Self>) -> Box<dyn Any>

source§

fn var_type_id(&self) -> TypeId

source§

fn get_any(&self) -> Box<dyn AnyVarValue>

source§

fn with_any(&self, read: &mut dyn FnMut(&dyn AnyVarValue))

source§

fn with_new_any(&self, read: &mut dyn FnMut(&dyn AnyVarValue)) -> bool

source§

fn set_any(&self, value: Box<dyn AnyVarValue>) -> Result<(), VarIsReadOnlyError>

source§

fn last_update(&self) -> VarUpdateId

source§

fn is_contextual(&self) -> bool

source§

fn capabilities(&self) -> VarCapability

source§

fn is_animating(&self) -> bool

source§

fn modify_importance(&self) -> usize

source§

fn hook_any( &self, pos_modify_action: Box<dyn Fn(&AnyVarHookArgs<'_>) -> bool + Send + Sync>, ) -> VarHandle

source§

fn hook_animation_stop( &self, handler: Box<dyn FnOnce() + Send>, ) -> Result<(), Box<dyn FnOnce() + Send>>

source§

fn strong_count(&self) -> usize

source§

fn weak_count(&self) -> usize

source§

fn actual_var_any(&self) -> BoxedAnyVar

source§

fn downgrade_any(&self) -> BoxedAnyWeakVar

source§

fn var_ptr(&self) -> VarPtr<'_>

source§

fn get_debug(&self) -> Txt

source§

fn update(&self) -> Result<(), VarIsReadOnlyError>

source§

fn map_debug(&self) -> BoxedVar<Txt>

Implementors§

source§

impl<I: VarValue, O: VarValue, S: Var<I>> AnyVar for MapRef<I, O, S>

source§

impl<I: VarValue, O: VarValue, S: Var<I>> AnyVar for MapRefBidi<I, O, S>

source§

impl<T, V> AnyVar for ArcFlatMapVar<T, V>
where T: VarValue, V: Var<T>,

source§

impl<T: VarValue> AnyVar for ArcVar<T>

source§

impl<T: VarValue> AnyVar for ContextVar<T>

source§

impl<T: VarValue> AnyVar for LocalVar<T>

source§

impl<T: VarValue> AnyVar for ArcMergeVar<T>

source§

impl<T: VarValue> AnyVar for ArcWhenVar<T>

source§

impl<T: VarValue> AnyVar for ContextualizedVar<T>

source§

impl<T: VarValue> AnyVar for BoxedVar<T>

source§

impl<T: VarValue, S: Var<T>> AnyVar for ArcCowVar<T, S>

source§

impl<T: VarValue, V: Var<T>> AnyVar for ReadOnlyVar<T, V>