Skip to main content

ferroui_controls/
assigned_binding.rs

1use ferroui_base::data::BindingBase;
2use std::ops::Deref;
3use std::rc::Rc;
4
5/// A binding held as the value of a property (a property that is assigned
6/// a binding rather than bound with it). Equality is identity.
7#[derive(Clone)]
8pub struct AssignedBinding(pub Rc<dyn BindingBase>);
9
10impl AssignedBinding {
11    /// Wraps a binding.
12    pub fn new(binding: Rc<dyn BindingBase>) -> Self {
13        Self(binding)
14    }
15}
16
17impl PartialEq for AssignedBinding {
18    fn eq(&self, other: &Self) -> bool {
19        std::ptr::addr_eq(Rc::as_ptr(&self.0), Rc::as_ptr(&other.0))
20    }
21}
22
23impl Deref for AssignedBinding {
24    type Target = dyn BindingBase;
25
26    fn deref(&self) -> &Self::Target {
27        &*self.0
28    }
29}
30
31impl From<Rc<dyn BindingBase>> for AssignedBinding {
32    fn from(value: Rc<dyn BindingBase>) -> Self {
33        Self(value)
34    }
35}