pub struct Property<T> { /* private fields */ }Implementations§
Source§impl<T: 'static + Clone + PartialEq> Property<T>
impl<T: 'static + Clone + PartialEq> Property<T>
pub fn new<U: Into<T>>(val: U) -> Self
pub fn binded_from(src_property: &Property<T>) -> Self
pub fn binded_c_from<TSrc: 'static + Clone + PartialEq, F: 'static + Fn(TSrc) -> T>( src_property: &Property<TSrc>, f: F, ) -> Self
pub fn binded_to(dst_property: &Property<T>, init_value: T) -> Self
pub fn binded_c_to<TDst: 'static + Clone + PartialEq, F: 'static + Fn(T) -> TDst>( dst_property: &Property<TDst>, f: F, init_value: T, ) -> Self
pub fn binded_two_way(other_property: &Property<T>) -> Self
pub fn binded_c_two_way<TOther, F1, F2>( other_property: &Property<TOther>, f1: F1, f2: F2, ) -> Self
pub fn set(&self, val: T)
pub fn change<F: 'static + Fn(T) -> T>(&self, f: F)
pub fn get(&self) -> T
pub fn read(&self) -> PropertyReadGuard<'_, T>
pub fn write(&self) -> PropertyWriteGuard<'_, T>
pub fn bind(&self, src_property: &Property<T>)
pub fn bind_c<TSrc: 'static + Clone + PartialEq, F: 'static + Fn(TSrc) -> T>( &self, src_property: &Property<TSrc>, f: F, )
Sourcepub fn bind_from_expr<F, R>(
expr_fn: F,
subscriptions: Vec<PropertySubscription>,
) -> Property<R>
pub fn bind_from_expr<F, R>( expr_fn: F, subscriptions: Vec<PropertySubscription>, ) -> Property<R>
Creates a new Property with value computed from an expression that depends on multiple source properties.
The resulting property automatically tracks changes to all source properties and recomputes its value when any of them changes.
§Arguments
expr_fn- A closure that computes the value of the resulting property. This closure must be'staticand typically requiresmovesemantics with cloned source properties.subscriptions- A vector ofPropertySubscriptionobjects created from source properties usingPropertySubscription::from_property().
§Example
use fui_core::{Property, PropertySubscription};
let first_name = Property::new("John".to_string());
let last_name = Property::new("Doe".to_string());
let full_name = Property::<String>::bind_from_expr(
{
let first_name = first_name.clone();
let last_name = last_name.clone();
move || format!("{} {}", first_name.get(), last_name.get())
},
vec![
PropertySubscription::from_property(&first_name),
PropertySubscription::from_property(&last_name),
]
);
assert_eq!(full_name.get(), "John Doe");
first_name.set("Jane".to_string());
assert_eq!(full_name.get(), "Jane Doe");pub fn on_changed<F: 'static + FnMut(T)>(&self, f: F) -> Subscription
Sourcepub fn add_bind_subscription(&self, subscription: Subscription)
pub fn add_bind_subscription(&self, subscription: Subscription)
Adds a subscription to the internal bind_handles collection. This is used by the ui! macro for automatic dependency tracking.
Trait Implementations§
Source§impl<V> From<&Property<Option<Rc<V>>>> for Box<dyn ObservableCollection<Rc<dyn ControlObject>>>
impl<V> From<&Property<Option<Rc<V>>>> for Box<dyn ObservableCollection<Rc<dyn ControlObject>>>
Source§impl<V> From<&Property<Rc<V>>> for Box<dyn ObservableCollection<Rc<dyn ControlObject>>>
impl<V> From<&Property<Rc<V>>> for Box<dyn ObservableCollection<Rc<dyn ControlObject>>>
Source§impl From<&Property<Rc<dyn ControlObject>>> for Box<dyn ObservableCollection<Rc<dyn ControlObject>>>
Converts Property to observable collection.
impl From<&Property<Rc<dyn ControlObject>>> for Box<dyn ObservableCollection<Rc<dyn ControlObject>>>
Converts Property to observable collection.
Source§impl<T> From<&Property<T>> for Property<T>
Allows to easily write one-way binding.
impl<T> From<&Property<T>> for Property<T>
Allows to easily write one-way binding.
Example:
ui! { Control { text_property: &vm.text }}
Source§impl<T> From<&mut Property<T>> for Property<T>
Allows to easily write two-way bindings.
impl<T> From<&mut Property<T>> for Property<T>
Allows to easily write two-way bindings.
Example:
ui! { Control { text_property: &mut vm.text }}
Source§impl<T, U> From<U> for Property<T>
Allows to convert types attributed with IntoProperty to Property.
impl<T, U> From<U> for Property<T>
Allows to convert types attributed with IntoProperty to Property
Cannot do it for all types at once, because then there is a conflict with binding conversions (tuples and properties used as source).
Example:
ui! { Control { int_property: 10, text_property: “My Text” }}
Source§impl<T> ObservableCollection<T> for Property<T>
ObservableCollection for Property.
impl<T> ObservableCollection<T> for Property<T>
ObservableCollection for Property.
Auto Trait Implementations§
impl<T> !Send for Property<T>
impl<T> !Sync for Property<T>
impl<T> Freeze for Property<T>
impl<T> RefUnwindSafe for Property<T>
impl<T> Unpin for Property<T>
impl<T> UnsafeUnpin for Property<T>
impl<T> UnwindSafe for Property<T>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T, TSrcColl> ObservableCollectionExt<T> for TSrcCollwhere
T: 'static + Clone,
TSrcColl: ObservableCollection<T> + 'static,
impl<T, TSrcColl> ObservableCollectionExt<T> for TSrcCollwhere
T: 'static + Clone,
TSrcColl: ObservableCollection<T> + 'static,
Source§fn map<TDst, F>(&self, f: F) -> ObservableCollectionMap<TDst>
fn map<TDst, F>(&self, f: F) -> ObservableCollectionMap<TDst>
Map creates new observable collection.
It keeps mapped copy of every item.
The only connection between it and original observable collection
is by subscribing on the on_changed event of the source collection,
so we don’t have to keep implicit reference to the source collection.
The on_change event of source collection keeps a weak reference to our handler.
Source§impl<TSrc, TSrcColl> ObservableCollectionFlatMapExt<TSrc> for TSrcCollwhere
TSrc: Clone + 'static,
TSrcColl: ObservableCollection<TSrc> + 'static,
impl<TSrc, TSrcColl> ObservableCollectionFlatMapExt<TSrc> for TSrcCollwhere
TSrc: Clone + 'static,
TSrcColl: ObservableCollection<TSrc> + 'static,
Source§fn flat_map<TDst, TDstColl, F>(&self, f: F) -> ObservableCollectionFlatMap<TDst>where
TDst: Clone + 'static,
TDstColl: ObservableCollection<TDst> + IntoIterator<Item = TDst>,
F: FnMut(&TSrc) -> TDstColl + 'static,
fn flat_map<TDst, TDstColl, F>(&self, f: F) -> ObservableCollectionFlatMap<TDst>where
TDst: Clone + 'static,
TDstColl: ObservableCollection<TDst> + IntoIterator<Item = TDst>,
F: FnMut(&TSrc) -> TDstColl + 'static,
Flat map creates new observable collection.
It keeps mapped copy of every item.
The only connection between it and original observable collection
is by subscribing on the on_changed event of the source collection,
so we don’t have to keep implicit reference to the source collection.
The on_change event of source collection keeps a weak reference to our handler.