dioxus_lib::prelude

Trait Writable

source
pub trait Writable: Readable {
    type Mut<'a, R: 'static + ?Sized>: DerefMut<Target = R>;

Show 13 methods // Required methods fn map_mut<I, U, F>(ref_: Self::Mut<'_, I>, f: F) -> Self::Mut<'_, U> where F: FnOnce(&mut I) -> &mut U, I: ?Sized, U: ?Sized; fn try_map_mut<I, U, F>( ref_: Self::Mut<'_, I>, f: F, ) -> Option<Self::Mut<'_, U>> where F: FnOnce(&mut I) -> Option<&mut U>, I: ?Sized, U: ?Sized; fn downcast_lifetime_mut<'a, 'b, T>( mut_: Self::Mut<'a, T>, ) -> Self::Mut<'b, T> where 'a: 'b, T: 'static + ?Sized; fn try_write_unchecked( &self, ) -> Result<Self::Mut<'static, Self::Target>, BorrowMutError>; // Provided methods fn write(&mut self) -> Self::Mut<'_, Self::Target> { ... } fn try_write( &mut self, ) -> Result<Self::Mut<'_, Self::Target>, BorrowMutError> { ... } fn write_unchecked(&self) -> Self::Mut<'static, Self::Target> { ... } fn with_mut<O>(&mut self, f: impl FnOnce(&mut Self::Target) -> O) -> O { ... } fn set(&mut self, value: Self::Target) where Self::Target: Sized { ... } fn toggle(&mut self) where Self::Target: Not<Output = Self::Target> + Clone { ... } fn index_mut<I>( &mut self, index: I, ) -> Self::Mut<'_, <Self::Target as Index<I>>::Output> where Self::Target: IndexMut<I> { ... } fn take(&mut self) -> Self::Target where Self::Target: Default { ... } fn replace(&mut self, value: Self::Target) -> Self::Target where Self::Target: Sized { ... }
}
Expand description

A trait for states that can be written to like crate::Signal. You may choose to accept this trait as a parameter instead of the concrete type to allow for more flexibility in your API.

§Example

enum MyEnum {
    String(String),
    Number(i32),
}

fn MyComponent(mut count: Signal<MyEnum>) -> Element {
    rsx! {
        button {
            onclick: move |_| {
                // You can use any methods from the Writable trait on Signals
                match &mut *count.write() {
                    MyEnum::String(s) => s.push('a'),
                    MyEnum::Number(n) => *n += 1,
                }
            },
            "Add value"
        }
    }
}

Required Associated Types§

source

type Mut<'a, R: 'static + ?Sized>: DerefMut<Target = R>

The type of the reference.

Required Methods§

source

fn map_mut<I, U, F>(ref_: Self::Mut<'_, I>, f: F) -> Self::Mut<'_, U>
where F: FnOnce(&mut I) -> &mut U, I: ?Sized, U: ?Sized,

Map the reference to a new type.

source

fn try_map_mut<I, U, F>( ref_: Self::Mut<'_, I>, f: F, ) -> Option<Self::Mut<'_, U>>
where F: FnOnce(&mut I) -> Option<&mut U>, I: ?Sized, U: ?Sized,

Try to map the reference to a new type.

source

fn downcast_lifetime_mut<'a, 'b, T>(mut_: Self::Mut<'a, T>) -> Self::Mut<'b, T>
where 'a: 'b, T: 'static + ?Sized,

Downcast a mutable reference in a RefMut to a more specific lifetime

This function enforces the variance of the lifetime parameter 'a in Ref.

source

fn try_write_unchecked( &self, ) -> Result<Self::Mut<'static, Self::Target>, BorrowMutError>

Try to get a mutable reference to the value without checking the lifetime. This will update any subscribers.

NOTE: This method is completely safe because borrow checking is done at runtime.

Provided Methods§

source

fn write(&mut self) -> Self::Mut<'_, Self::Target>

Get a mutable reference to the value. If the value has been dropped, this will panic.

source

fn try_write(&mut self) -> Result<Self::Mut<'_, Self::Target>, BorrowMutError>

Try to get a mutable reference to the value.

source

fn write_unchecked(&self) -> Self::Mut<'static, Self::Target>

Get a mutable reference to the value without checking the lifetime. This will update any subscribers.

NOTE: This method is completely safe because borrow checking is done at runtime.

source

fn with_mut<O>(&mut self, f: impl FnOnce(&mut Self::Target) -> O) -> O

Run a function with a mutable reference to the value. If the value has been dropped, this will panic.

source

fn set(&mut self, value: Self::Target)
where Self::Target: Sized,

Set the value of the signal. This will trigger an update on all subscribers.

source

fn toggle(&mut self)
where Self::Target: Not<Output = Self::Target> + Clone,

Invert the boolean value of the signal. This will trigger an update on all subscribers.

source

fn index_mut<I>( &mut self, index: I, ) -> Self::Mut<'_, <Self::Target as Index<I>>::Output>
where Self::Target: IndexMut<I>,

Index into the inner value and return a reference to the result.

source

fn take(&mut self) -> Self::Target
where Self::Target: Default,

Takes the value out of the Signal, leaving a Default in its place.

source

fn replace(&mut self, value: Self::Target) -> Self::Target
where Self::Target: Sized,

Replace the value in the Signal, returning the old value.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<T, R> Writable for Global<T, R>
where T: Clone + 'static + Writable<Target = R> + InitializeFromFunction<R>, R: 'static,

source§

type Mut<'a, Read: 'static + ?Sized> = <T as Writable>::Mut<'a, Read>

source§

impl<T, S> Writable for CopyValue<T, S>
where T: 'static, S: Storage<T>,

source§

type Mut<'a, R: 'static + ?Sized> = <S as AnyStorage>::Mut<'a, R>

source§

impl<T, S> Writable for Signal<T, S>
where T: 'static, S: Storage<SignalData<T>>,

source§

type Mut<'a, R: 'static + ?Sized> = Write<'a, R, S>