pub struct DATA;Expand description
Data context and validation.
This service enables data flow from a context to descendants, and from descendants up-to contexts, like an anonymous context var.
Arbitrary data can be set on a context using the data property and retrieved using DATA.get or DATA.req.
Only one data entry and type can exist in a context, nested data properties override the parent data and type in their context.
Annotation on the data can be set back using DATA.annotate and can be retrieved using the get_data_notes property,
annotations are classified by DataNoteLevel, including INFO, WARN and ERROR. For each level there are specialized
methods and properties, as an example, the DATA.invalidate is used to set an error note, and the get_data_error_txt
property gets the error formatted for display. Data notes are aggregated from descendants up-to the context, continuing
up to outer nested contexts too, this means that you can get data errors for a form field by setting get_data_error_txt on
the field widget, and get all form errors from that field and others by also setting get_data_error_txt in the form widget.
Implementations§
Source§impl DATA
impl DATA
Sourcepub fn get<T>(&self, fallback: impl Fn() -> T + Send + Sync + 'static) -> Var<T>where
T: VarValue,
pub fn get<T>(&self, fallback: impl Fn() -> T + Send + Sync + 'static) -> Var<T>where
T: VarValue,
Gets a var of T, if the contextual DATA type is not T the fallback closure is called to produce a value.
§Capabilities
The returned var is contextual, it will get the data var in the final context it is used not on the context that calls this method.
Sourcepub fn get_any(&self) -> AnyVar
pub fn get_any(&self) -> AnyVar
Get the current context variable.
Note that this is different from get, the return variable is “actualized” on the calling context, not on the first var use context.
Sourcepub fn value_type(&self) -> TypeId
pub fn value_type(&self) -> TypeId
Gets the current context value type.
Sourcepub fn value_type_name(&self) -> &'static str
pub fn value_type_name(&self) -> &'static str
Gets the current context value type name.
Sourcepub fn annotate(
&self,
level: DataNoteLevel,
note: impl DataNoteValue,
) -> DataNoteHandle
pub fn annotate( &self, level: DataNoteLevel, note: impl DataNoteValue, ) -> DataNoteHandle
Insert a data note in the current context.
The note will stay in context until the context is unloaded or the handle is dropped.
Sourcepub fn inform(&self, note: impl DataNoteValue) -> DataNoteHandle
pub fn inform(&self, note: impl DataNoteValue) -> DataNoteHandle
Insert an INFO note in the current context.
The note will stay in context until the context is unloaded or the handle is dropped.
Sourcepub fn warn(&self, note: impl DataNoteValue) -> DataNoteHandle
pub fn warn(&self, note: impl DataNoteValue) -> DataNoteHandle
Insert a WARN note in the current context.
The note will stay in context until the context is unloaded or the handle is dropped.
Sourcepub fn invalidate(&self, note: impl DataNoteValue) -> DataNoteHandle
pub fn invalidate(&self, note: impl DataNoteValue) -> DataNoteHandle
Insert an ERROR note in the current context.
The note will stay in context until the context is unloaded or the handle is dropped.
Sourcepub fn note_color(&self, level: impl IntoVar<DataNoteLevel>) -> Var<Rgba>
pub fn note_color(&self, level: impl IntoVar<DataNoteLevel>) -> Var<Rgba>
Read-only variable that is the best color for the note level in the context of the current color scheme.
If the level is not found, gets the nearest less than level, if no color is set in the context gets
the black/white for dark/light.
The color can be used directly as text color, it probably needs mixing or desaturating to use as background.
Sourcepub fn info_color(&self) -> Var<Rgba>
pub fn info_color(&self) -> Var<Rgba>
Read-only variable that is the best color for INFO notes in the context of the current color scheme.
The color can be used directly as text color, it probably needs mixing or desaturating to use as background.
Sourcepub fn warn_color(&self) -> Var<Rgba>
pub fn warn_color(&self) -> Var<Rgba>
Read-only variable that is the best color for WARN notes in the context of the current color scheme.
The color can be used directly as text color, it probably needs mixing or desaturating to use as background.
Sourcepub fn error_color(&self) -> Var<Rgba>
pub fn error_color(&self) -> Var<Rgba>
Read-only variable that is the best color for ERROR notes in the context of the current color scheme.
The color can be used directly as text color, it probably needs mixing or desaturating to use as background.
Auto Trait Implementations§
impl Freeze for DATA
impl RefUnwindSafe for DATA
impl Send for DATA
impl Sync for DATA
impl Unpin for DATA
impl UnwindSafe for DATA
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
§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>. Box<dyn Any> can
then be further downcast into Box<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>. Rc<Any> 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> DowncastSync for T
impl<T> DowncastSync for T
§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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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