Skip to main content

ferroui_controls/templates/
i_data_template.rs

1use super::{IRecyclingDataTemplate, ITemplateWithParam, ITreeDataTemplate, ITypedDataTemplate};
2use crate::Control;
3use ferroui_base::{BoxedValue, Ref};
4
5/// Interface representing a template used to build a control for a piece of
6/// data.
7pub trait IDataTemplate: ITemplateWithParam<Option<BoxedValue>, Option<Ref<Control>>> {
8    /// Checks to see if this data template matches the specified data.
9    fn match_(&self, data: Option<&BoxedValue>) -> bool;
10
11    /// The template viewed as a recycling data template, if it is one.
12    fn as_recycling_data_template(&self) -> Option<&dyn IRecyclingDataTemplate> {
13        None
14    }
15
16    /// The template viewed as a typed data template, if it is one.
17    fn as_typed_data_template(&self) -> Option<&dyn ITypedDataTemplate> {
18        None
19    }
20
21    /// The template viewed as a tree data template, if it is one.
22    fn as_tree_data_template(&self) -> Option<&dyn ITreeDataTemplate> {
23        None
24    }
25
26    /// The implementing value, for casting to its concrete type
27    /// (`as_any()?.downcast_ref::<T>()`): the equivalent of `is`/`as` on the
28    /// contract. `None` for an implementation that does not expose itself.
29    fn as_any(&self) -> Option<&dyn std::any::Any> {
30        None
31    }
32}
33
34impl PartialEq for dyn IDataTemplate {
35    fn eq(&self, other: &Self) -> bool {
36        std::ptr::addr_eq(self as *const Self, other as *const Self)
37    }
38}