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§
Sourcetype WriteMetadata
type WriteMetadata
Additional data associated with the write reference.
Required Methods§
Sourcefn try_write_unchecked(
&self,
) -> Result<WritableRef<'static, Self>, BorrowMutError>where
Self::Target: 'static,
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.