Writable

Trait Writable 

Source
pub trait Writable: Readable {
    type WriteMetadata;

    // Required method
    fn try_write_unchecked(
        &self,
    ) -> Result<WritableRef<'static, Self>, BorrowMutError>
       where Self::Target: 'static;
}
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 WriteMetadata

Additional data associated with the write reference.

Required Methods§

Source

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

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.

Implementors§

Source§

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

Source§

impl<T, S: Storage<T>> Writable for CopyValue<T, S>

Source§

impl<T: 'static + PartialEq> Writable for Memo<T>

Source§

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

Source§

type WriteMetadata = SignalSubscriberDrop<T, S>

Source§

impl<T: ?Sized, S: BoxedSignalStorage<T>> Writable for WriteSignal<T, S>

Source§

impl<V, O, F, FMut> Writable for MappedMutSignal<O, V, F, FMut>
where O: ?Sized, V: Writable, V::Target: 'static, F: Fn(&V::Target) -> &O, FMut: Fn(&mut V::Target) -> &mut O,