Skip to main content

ferroui_base/data/core/plugins/
property_error.rs

1use super::{AccessorListener, IPropertyAccessor};
2use crate::data::core::ValueType;
3use crate::data::{BindingError, BindingNotification, BindingPriority};
4use crate::reactive::IDisposable;
5use crate::BoxedValue;
6use std::rc::Rc;
7
8/// An [`IPropertyAccessor`] that represents an error.
9pub struct PropertyError {
10    error: BoxedValue,
11}
12
13impl PropertyError {
14    pub fn new(error: BindingNotification) -> Self {
15        Self { error: Rc::new(error) }
16    }
17}
18
19impl IDisposable for PropertyError {
20    fn dispose(&self) {}
21}
22
23impl IPropertyAccessor for PropertyError {
24    fn property_type(&self) -> Option<ValueType> {
25        None
26    }
27
28    fn value(&self) -> Option<BoxedValue> {
29        Some(self.error.clone())
30    }
31
32    fn set_value(&self, _value: Option<&BoxedValue>, _priority: BindingPriority) -> Result<bool, BindingError> {
33        Ok(false)
34    }
35
36    fn subscribe(&self, listener: AccessorListener) {
37        listener(Some(self.error.clone()));
38    }
39
40    fn unsubscribe(&self) {}
41}