Skip to main content

ferroui_base/data/
binding_operations.rs

1use crate::data::BindingExpressionBase;
2use crate::{BoxedValue, DoNothingType, FerroObject, FerroProperty};
3use std::rc::Rc;
4
5/// Static members related to bindings.
6pub struct BindingOperations;
7
8impl BindingOperations {
9    /// The marker value that tells a binding target to do nothing: the
10    /// binding value is ignored.
11    pub fn do_nothing() -> BoxedValue {
12        crate::ferro_thread_local! {
13            static DO_NOTHING: BoxedValue = Rc::new(DoNothingType);
14        }
15        DO_NOTHING.with(Rc::clone)
16    }
17
18    /// Whether `value` is the do-nothing marker.
19    #[inline]
20    pub fn is_do_nothing(value: Option<&BoxedValue>) -> bool {
21        value.is_some_and(|v| v.is::<DoNothingType>())
22    }
23
24    /// Whether `value` is the unset marker.
25    #[inline]
26    pub fn is_unset(value: Option<&BoxedValue>) -> bool {
27        value.is_some_and(|v| v.is::<crate::UnsetValueType>())
28    }
29
30    /// Retrieves the binding expression that is currently active on the
31    /// specified property, if any.
32    pub fn get_binding_expression_base(
33        target: &FerroObject,
34        property: &'static FerroProperty,
35    ) -> Option<Rc<dyn BindingExpressionBase>> {
36        target.get_expression(property)
37    }
38}