Skip to main content

Property

Struct Property 

Source
pub struct Property<T> { /* private fields */ }

Implementations§

Source§

impl<T: 'static + Clone + PartialEq> Property<T>

Source

pub fn new<U: Into<T>>(val: U) -> Self

Source

pub fn binded_from(src_property: &Property<T>) -> Self

Source

pub fn binded_c_from<TSrc: 'static + Clone + PartialEq, F: 'static + Fn(TSrc) -> T>( src_property: &Property<TSrc>, f: F, ) -> Self

Source

pub fn binded_to(dst_property: &Property<T>, init_value: T) -> Self

Source

pub fn binded_c_to<TDst: 'static + Clone + PartialEq, F: 'static + Fn(T) -> TDst>( dst_property: &Property<TDst>, f: F, init_value: T, ) -> Self

Source

pub fn binded_two_way(other_property: &Property<T>) -> Self

Source

pub fn binded_c_two_way<TOther, F1, F2>( other_property: &Property<TOther>, f1: F1, f2: F2, ) -> Self
where TOther: 'static + Clone + PartialEq, F1: 'static + Fn(TOther) -> T, F2: 'static + Fn(T) -> TOther,

Source

pub fn set(&self, val: T)

Source

pub fn change<F: 'static + Fn(T) -> T>(&self, f: F)

Source

pub fn get(&self) -> T

Source

pub fn read(&self) -> PropertyReadGuard<'_, T>

Source

pub fn write(&self) -> PropertyWriteGuard<'_, T>

Source

pub fn bind(&self, src_property: &Property<T>)

Source

pub fn bind_c<TSrc: 'static + Clone + PartialEq, F: 'static + Fn(TSrc) -> T>( &self, src_property: &Property<TSrc>, f: F, )

Source

pub fn bind_from_expr<F, R>( expr_fn: F, subscriptions: Vec<PropertySubscription>, ) -> Property<R>
where R: 'static + Clone + PartialEq, F: 'static + Fn() -> 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 'static and typically requires move semantics with cloned source properties.
  • subscriptions - A vector of PropertySubscription objects created from source properties using PropertySubscription::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");
Source

pub fn on_changed<F: 'static + FnMut(T)>(&self, f: F) -> Subscription

Source

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<T: 'static + Clone + PartialEq> Clone for Property<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<V> From<&Property<Option<Rc<V>>>> for Box<dyn ObservableCollection<Rc<dyn ControlObject>>>
where V: 'static + ViewModel + PartialEq,

Source§

fn from(src: &Property<Option<Rc<V>>>) -> Self

Converts to this type from the input type.
Source§

impl<V> From<&Property<Rc<V>>> for Box<dyn ObservableCollection<Rc<dyn ControlObject>>>
where V: 'static + ViewModel + PartialEq,

Source§

fn from(src: &Property<Rc<V>>) -> Self

Converts to this type from the input type.
Source§

impl From<&Property<Rc<dyn ControlObject>>> for Box<dyn ObservableCollection<Rc<dyn ControlObject>>>

Converts Property to observable collection.

Source§

fn from(src: &Property<Rc<dyn ControlObject>>) -> Self

Converts to this type from the input type.
Source§

impl<T> From<&Property<T>> for Property<T>
where T: 'static + Clone + PartialEq,

Allows to easily write one-way binding.

Example:

ui! { Control { text_property: &vm.text }}

Source§

fn from(value: &Property<T>) -> Property<T>

Converts to this type from the input type.
Source§

impl<T> From<&mut Property<T>> for Property<T>
where T: 'static + Clone + PartialEq,

Allows to easily write two-way bindings.

Example:

ui! { Control { text_property: &mut vm.text }}

Source§

fn from(value: &mut Property<T>) -> Property<T>

Converts to this type from the input type.
Source§

impl<T, U> From<U> for Property<T>
where T: 'static + Clone + PartialEq, U: Into<T> + IntoProperty,

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§

fn from(value: U) -> Property<T>

Converts to this type from the input type.
Source§

impl<T> ObservableCollection<T> for Property<T>
where T: 'static + Clone + PartialEq,

ObservableCollection for Property.

Source§

fn len(&self) -> usize

Source§

fn get(&self, index: usize) -> Option<T>

Source§

fn on_changed(&self, f: Box<dyn FnMut(VecDiff<T>)>) -> Option<Subscription>

Source§

impl<T> ObservableCollection<T> for Property<Option<T>>
where T: 'static + Clone + PartialEq,

Source§

fn len(&self) -> usize

Source§

fn get(&self, index: usize) -> Option<T>

Source§

fn on_changed(&self, f: Box<dyn FnMut(VecDiff<T>)>) -> Option<Subscription>

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, TSrcColl> ObservableCollectionExt<T> for TSrcColl
where T: 'static + Clone, TSrcColl: ObservableCollection<T> + 'static,

Source§

fn map<TDst, F>(&self, f: F) -> ObservableCollectionMap<TDst>
where TDst: 'static + Clone, F: 'static + Fn(&T) -> 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 TSrcColl
where 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,

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.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.