Skip to main content

Writable

Trait Writable 

Source
pub trait Writable: Readable {
    type WriteMetadata;

    // Required method
    fn try_write_unchecked(
        &self,
    ) -> Result<WriteLock<'static, Self::Target, Self::Storage, Self::WriteMetadata>, BorrowMutError>
       where Self::Target: 'static;
}
Available on crate feature prelude only.
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<WriteLock<'static, Self::Target, Self::Storage, Self::WriteMetadata>, 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.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<Index, Write, K, V, St> Writable for GetWrite<Index, Write>
where Write: Writable<Target = HashMap<K, V, St>>, Index: Hash + Eq + 'static, K: Borrow<Index> + Eq + Hash + 'static, St: BuildHasher + 'static,

Source§

type WriteMetadata = <Write as Writable>::WriteMetadata

Source§

fn try_write_unchecked( &self, ) -> Result<WriteLock<'static, <GetWrite<Index, Write> as Readable>::Target, <GetWrite<Index, Write> as Readable>::Storage, <GetWrite<Index, Write> as Writable>::WriteMetadata>, BorrowMutError>
where <GetWrite<Index, Write> as Readable>::Target: 'static,

Source§

impl<Index, Write, K, V> Writable for GetWrite<Index, Write>
where Write: Writable<Target = BTreeMap<K, V>>, Index: Ord + 'static, K: Borrow<Index> + Ord + 'static,

Source§

type WriteMetadata = <Write as Writable>::WriteMetadata

Source§

fn try_write_unchecked( &self, ) -> Result<WriteLock<'static, <GetWrite<Index, Write> as Readable>::Target, <GetWrite<Index, Write> as Readable>::Storage, <GetWrite<Index, Write> as Writable>::WriteMetadata>, BorrowMutError>
where <GetWrite<Index, Write> as Readable>::Target: 'static,

Source§

impl<Index, Write> Writable for IndexWrite<Index, Write>
where Write: Writable, <Write as Readable>::Target: IndexMut<Index> + 'static, Index: Clone,

Source§

type WriteMetadata = <Write as Writable>::WriteMetadata

Source§

fn try_write_unchecked( &self, ) -> Result<WriteLock<'static, <IndexWrite<Index, Write> as Readable>::Target, <IndexWrite<Index, Write> as Readable>::Storage, <IndexWrite<Index, Write> as Writable>::WriteMetadata>, BorrowMutError>
where <IndexWrite<Index, Write> as Readable>::Target: 'static,

Source§

impl<Lens> Writable for SelectorScope<Lens>
where Lens: Writable,

Implementors§

Source§

impl<T, Lens> Writable for Store<T, Lens>
where Lens: Writable<Target = T>, T: 'static + ?Sized,

Source§

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

Source§

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

Source§

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

Source§

type WriteMetadata = SignalSubscriberDrop<T, S>

Source§

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

Source§

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

Source§

impl<T> Writable for Resource<T>

Source§

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