Store

Struct Store 

Source
pub struct Store<T, Lens = WriteSignal<T>>
where T: ?Sized,
{ /* private fields */ }
Available on crate feature prelude only.
Expand description

Stores are a reactive type built for nested data structures. Each store will lazily create signals for each field/member of the data structure as needed.

By default stores act a lot like dioxus_signals::Signals, but they provide more granular subscriptions without requiring nested signals. You should derive Store on your data structures to generate selectors that let you scope the store to a specific part of your data.

You can also use the #[store] macro on an impl block to add any additional methods to your store with an extension trait. This lets you add methods to the store even though the type is not defined in your crate.

§Example

use dioxus::prelude::*;
use dioxus_stores::*;

fn main() {
    dioxus::launch(app);
}

// Deriving the store trait provides methods to scope the store to specific parts of your data structure.
// The `Store` macro generates a `count` and `children` method for the `CounterTree` struct.
#[derive(Store, Default)]
struct CounterTree {
    count: i32,
    children: Vec<CounterTree>,
}

// The store macro generates an extension trait with additional methods for the store based on the impl block.
#[store]
impl<Lens> Store<CounterTree, Lens> {
    // Methods that take &self automatically require the lens to implement `Readable` which lets you read the store.
    fn sum(&self) -> i32 {
       self.count().cloned() + self.children().iter().map(|c| c.sum()).sum::<i32>()
    }
}

fn app() -> Element {
    let value = use_store(Default::default);

    rsx! {
        Tree {
            value
        }
    }
}

#[component]
fn Tree(value: Store<CounterTree>) -> Element {
    // Calling the generated `count` method returns a new store that can only
    // read and write the count field
    let mut count = value.count();
    let mut children = value.children();
    rsx! {
        button {
            // Incrementing the count will only rerun parts of the app that have read the count field
            onclick: move |_| count += 1,
            "Increment"
        }
        button {
            // Stores are aware of data structures like `Vec` and `Hashmap`. When we push an item to the vec
            // it will only rerun the parts of the app that depend on the length of the vec
            onclick: move |_| children.push(Default::default()),
            "Push child"
        }
        "sum: {value.sum()}"
        ul {
            // Iterating over the children gives us stores scoped to each child.
            for value in children.iter() {
                li {
                    Tree { value }
                }
            }
        }
    }
}

Implementations§

Source§

impl<Lens, K, V> Store<BTreeMap<K, V>, Lens>
where Lens: Readable<Target = BTreeMap<K, V>> + 'static, K: 'static, V: 'static,

Source

pub fn len(&self) -> usize

Get the length of the BTreeMap. This method will track the store shallowly and only cause re-runs when items are added or removed from the map, not when existing values are modified.

§Example
use dioxus_stores::*;
use dioxus::prelude::*;
use std::collections::BTreeMap;
let mut store = use_store(|| BTreeMap::new());
assert_eq!(store.len(), 0);
store.insert(0, "value".to_string());
assert_eq!(store.len(), 1);
Source

pub fn is_empty(&self) -> bool

Check if the BTreeMap is empty. This method will track the store shallowly and only cause re-runs when items are added or removed from the map, not when existing values are modified.

§Example
use dioxus_stores::*;
use dioxus::prelude::*;
use std::collections::BTreeMap;
let mut store = use_store(|| BTreeMap::new());
assert!(store.is_empty());
store.insert(0, "value".to_string());
assert!(!store.is_empty());
Source

pub fn iter( &self, ) -> impl ExactSizeIterator + DoubleEndedIterator + FusedIterator
where K: Hash + Ord + Clone, Lens: Clone,

Iterate over the current entries in the BTreeMap, returning a tuple of the key and a store for the value. This method will track the store shallowly and only cause re-runs when items are added or removed from the map, not when existing values are modified.

§Example
use dioxus_stores::*;
use dioxus::prelude::*;
use std::collections::BTreeMap;
let mut store = use_store(|| BTreeMap::new());
store.insert(0, "value1".to_string());
store.insert(1, "value2".to_string());
for (key, value_store) in store.iter() {
    println!("{}: {}", key, value_store.read());
}
Source

pub fn values( &self, ) -> impl ExactSizeIterator + DoubleEndedIterator + FusedIterator
where K: Hash + Ord + Clone, Lens: Clone,

Get an iterator over the values in the BTreeMap. This method will track the store shallowly and only cause re-runs when items are added or removed from the map, not when existing values are modified.

§Example
use dioxus_stores::*;
use dioxus::prelude::*;
use std::collections::BTreeMap;
let mut store = use_store(|| BTreeMap::new());
store.insert(0, "value1".to_string());
store.insert(1, "value2".to_string());
for value_store in store.values() {
    println!("{}", value_store.read());
}
Source

pub fn insert(&mut self, key: K, value: V)
where K: Ord, Lens: Writable,

Insert a new key-value pair into the BTreeMap. This method will mark the store as shallowly dirty, causing re-runs of any reactive scopes that depend on the shape of the map.

§Example
use dioxus_stores::*;
use dioxus::prelude::*;
use std::collections::BTreeMap;
let mut store = use_store(|| BTreeMap::new());
assert!(store.get(0).is_none());
store.insert(0, "value".to_string());
assert_eq!(store.get(0).unwrap().cloned(), "value".to_string());
Source

pub fn remove<Q>(&mut self, key: &Q) -> Option<V>
where Q: Ord + 'static + ?Sized, K: Borrow<Q> + Ord, Lens: Writable,

Remove a key-value pair from the BTreeMap. This method will mark the store as shallowly dirty, causing re-runs of any reactive scopes that depend on the shape of the map or the value of the removed key.

§Example
use dioxus_stores::*;
use dioxus::prelude::*;
use std::collections::BTreeMap;
let mut store = use_store(|| BTreeMap::new());
store.insert(0, "value".to_string());
assert_eq!(store.get(0).unwrap().cloned(), "value".to_string());
let removed_value = store.remove(&0);
assert_eq!(removed_value, Some("value".to_string()));
assert!(store.get(0).is_none());
Source

pub fn clear(&mut self)
where Lens: Writable,

Clear the BTreeMap, removing all key-value pairs. This method will mark the store as shallowly dirty, causing re-runs of any reactive scopes that depend on the shape of the map.

§Example
use dioxus_stores::*;
use dioxus::prelude::*;
use std::collections::BTreeMap;
let mut store = use_store(|| BTreeMap::new());
store.insert(1, "value1".to_string());
store.insert(2, "value2".to_string());
assert_eq!(store.len(), 2);
store.clear();
assert!(store.is_empty());
Source

pub fn retain(&mut self, f: impl FnMut(&K, &V) -> bool)
where Lens: Writable, K: Ord,

Retain only the key-value pairs that satisfy the given predicate. This method will mark the store as shallowly dirty, causing re-runs of any reactive scopes that depend on the shape of the map or the values retained.

§Example
use dioxus_stores::*;
use dioxus::prelude::*;
use std::collections::BTreeMap;
let mut store = use_store(|| BTreeMap::new());
store.insert(1, "value1".to_string());
store.insert(2, "value2".to_string());
store.retain(|key, value| *key == 1);
assert_eq!(store.len(), 1);
assert!(store.get(1).is_some());
assert!(store.get(2).is_none());
Source

pub fn contains_key<Q>(&self, key: &Q) -> bool
where Q: Ord + 'static + ?Sized, K: Borrow<Q> + Ord,

Check if the BTreeMap contains a key. This method will track the store shallowly and only cause re-runs when items are added or removed from the map, not when existing values are modified.

§Example
use dioxus_stores::*;
use dioxus::prelude::*;
use std::collections::BTreeMap;
let mut store = use_store(|| BTreeMap::new());
assert!(!store.contains_key(&0));
store.insert(0, "value".to_string());
assert!(store.contains_key(&0));
Source

pub fn get<Q>(self, key: Q) -> Option<Store<V, GetWrite<Q, Lens>>>
where Q: Hash + Ord + 'static, K: Borrow<Q> + Ord,

Get a store for the value associated with the given key. This method creates a new store scope that tracks just changes to the value associated with the key.

§Example
use dioxus_stores::*;
use dioxus::prelude::*;
use std::collections::BTreeMap;
let mut store = use_store(|| BTreeMap::new());
assert!(store.get(0).is_none());
store.insert(0, "value".to_string());
assert_eq!(store.get(0).unwrap().cloned(), "value".to_string());
Source

pub fn get_unchecked<Q>(self, key: Q) -> Store<V, GetWrite<Q, Lens>>
where Q: Hash + Ord + 'static, K: Borrow<Q> + Ord,

Get a store for the value associated with the given key without checking if the key exists. This method creates a new store scope that tracks just changes to the value associated with the key.

This is not unsafe, but it will panic when you try to read the value if it does not exist.

§Example
use dioxus_stores::*;
use dioxus::prelude::*;
use std::collections::BTreeMap;
let mut store = use_store(|| BTreeMap::new());
store.insert(0, "value".to_string());
assert_eq!(store.get_unchecked(0).cloned(), "value".to_string());
Source§

impl<Lens, T> Store<T, Lens>
where Lens: Readable<Target = T> + 'static, T: DerefMut + 'static,

Source

pub fn deref( self, ) -> Store<<T as Deref>::Target, MappedMutSignal<<T as Deref>::Target, Lens, fn(&<Lens as Readable>::Target) -> &<T as Deref>::Target, fn(&mut <Lens as Readable>::Target) -> &mut <T as Deref>::Target>>

Returns a store that dereferences the original value. The dereferenced store shares the same subscriptions and tracking as the original store, but allows you to access the methods of the underlying type.

§Example
use dioxus_stores::*;
let store = use_store(|| Box::new(vec![1, 2, 3]));
let deref_store = store.deref();
// The dereferenced store can access the store methods of the underlying type.
assert_eq!(deref_store.len(), 3);
Source§

impl<Lens, K, V, St> Store<HashMap<K, V, St>, Lens>
where Lens: Readable<Target = HashMap<K, V, St>> + 'static, K: 'static, V: 'static, St: 'static,

Source

pub fn len(&self) -> usize

Get the length of the HashMap. This method will track the store shallowly and only cause re-runs when items are added or removed from the map, not when existing values are modified.

§Example
use dioxus_stores::*;
use dioxus::prelude::*;
use std::collections::HashMap;
let mut store = use_store(|| HashMap::new());
assert_eq!(store.len(), 0);
store.insert(0, "value".to_string());
assert_eq!(store.len(), 1);
Source

pub fn is_empty(&self) -> bool

Check if the HashMap is empty. This method will track the store shallowly and only cause re-runs when items are added or removed from the map, not when existing values are modified.

§Example
use dioxus_stores::*;
use dioxus::prelude::*;
use std::collections::HashMap;
let mut store = use_store(|| HashMap::new());
assert!(store.is_empty());
store.insert(0, "value".to_string());
assert!(!store.is_empty());
Source

pub fn iter( &self, ) -> impl ExactSizeIterator + DoubleEndedIterator + FusedIterator
where K: Eq + Hash + Clone, St: BuildHasher, Lens: Clone,

Iterate over the current entries in the HashMap, returning a tuple of the key and a store for the value. This method will track the store shallowly and only cause re-runs when items are added or removed from the map, not when existing values are modified.

§Example
use dioxus_stores::*;
use dioxus::prelude::*;
use std::collections::HashMap;
let mut store = use_store(|| HashMap::new());
store.insert(0, "value1".to_string());
store.insert(1, "value2".to_string());
for (key, value_store) in store.iter() {
    println!("{}: {}", key, value_store.read());
}
Source

pub fn values( &self, ) -> impl ExactSizeIterator + DoubleEndedIterator + FusedIterator
where K: Eq + Hash + Clone, St: BuildHasher, Lens: Clone,

Get an iterator over the values in the HashMap. This method will track the store shallowly and only cause re-runs when items are added or removed from the map, not when existing values are modified.

§Example
use dioxus_stores::*;
use dioxus::prelude::*;
use std::collections::HashMap;
let mut store = use_store(|| HashMap::new());
store.insert(0, "value1".to_string());
store.insert(1, "value2".to_string());
for value_store in store.values() {
    println!("{}", value_store.read());
}
Source

pub fn insert(&mut self, key: K, value: V)
where K: Eq + Hash, St: BuildHasher, Lens: Writable,

Insert a new key-value pair into the HashMap. This method will mark the store as shallowly dirty, causing re-runs of any reactive scopes that depend on the shape of the map.

§Example
use dioxus_stores::*;
use dioxus::prelude::*;
use std::collections::HashMap;
let mut store = use_store(|| HashMap::new());
assert!(store.get(0).is_none());
store.insert(0, "value".to_string());
assert_eq!(store.get(0).unwrap().cloned(), "value".to_string());
Source

pub fn remove<Q>(&mut self, key: &Q) -> Option<V>
where Q: Hash + Eq + 'static + ?Sized, K: Borrow<Q> + Eq + Hash, St: BuildHasher, Lens: Writable,

Remove a key-value pair from the HashMap. This method will mark the store as shallowly dirty, causing re-runs of any reactive scopes that depend on the shape of the map or the value of the removed key.

§Example
use dioxus_stores::*;
use dioxus::prelude::*;
use std::collections::HashMap;
let mut store = use_store(|| HashMap::new());
store.insert(0, "value".to_string());
assert_eq!(store.get(0).unwrap().cloned(), "value".to_string());
let removed_value = store.remove(&0);
assert_eq!(removed_value, Some("value".to_string()));
assert!(store.get(0).is_none());
Source

pub fn clear(&mut self)
where Lens: Writable,

Clear the HashMap, removing all key-value pairs. This method will mark the store as shallowly dirty, causing re-runs of any reactive scopes that depend on the shape of the map.

§Example
use dioxus_stores::*;
use dioxus::prelude::*;
use std::collections::HashMap;
let mut store = use_store(|| HashMap::new());
store.insert(1, "value1".to_string());
store.insert(2, "value2".to_string());
assert_eq!(store.len(), 2);
store.clear();
assert!(store.is_empty());
Source

pub fn retain(&mut self, f: impl FnMut(&K, &V) -> bool)
where Lens: Writable,

Retain only the key-value pairs that satisfy the given predicate. This method will mark the store as shallowly dirty, causing re-runs of any reactive scopes that depend on the shape of the map or the values retained.

§Example
use dioxus_stores::*;
use dioxus::prelude::*;
use std::collections::HashMap;
let mut store = use_store(|| HashMap::new());
store.insert(1, "value1".to_string());
store.insert(2, "value2".to_string());
store.retain(|key, value| *key == 1);
assert_eq!(store.len(), 1);
assert!(store.get(1).is_some());
assert!(store.get(2).is_none());
Source

pub fn contains_key<Q>(&self, key: &Q) -> bool
where Q: Hash + Eq + 'static + ?Sized, K: Borrow<Q> + Eq + Hash, St: BuildHasher,

Check if the HashMap contains a key. This method will track the store shallowly and only cause re-runs when items are added or removed from the map, not when existing values are modified.

§Example
use dioxus_stores::*;
use dioxus::prelude::*;
use std::collections::HashMap;
let mut store = use_store(|| HashMap::new());
assert!(!store.contains_key(&0));
store.insert(0, "value".to_string());
assert!(store.contains_key(&0));
Source

pub fn get<Q>(self, key: Q) -> Option<Store<V, GetWrite<Q, Lens>>>
where Q: Hash + Eq + 'static, K: Borrow<Q> + Eq + Hash, St: BuildHasher,

Get a store for the value associated with the given key. This method creates a new store scope that tracks just changes to the value associated with the key.

§Example
use dioxus_stores::*;
use dioxus::prelude::*;
use std::collections::HashMap;
let mut store = use_store(|| HashMap::new());
assert!(store.get(0).is_none());
store.insert(0, "value".to_string());
assert_eq!(store.get(0).unwrap().cloned(), "value".to_string());
Source

pub fn get_unchecked<Q>(self, key: Q) -> Store<V, GetWrite<Q, Lens>>
where Q: Hash + Eq + 'static, K: Borrow<Q> + Eq + Hash, St: BuildHasher,

Get a store for the value associated with the given key without checking if the key exists. This method creates a new store scope that tracks just changes to the value associated with the key.

This is not unsafe, but it will panic when you try to read the value if it does not exist.

§Example
use dioxus_stores::*;
use dioxus::prelude::*;
use std::collections::HashMap;
let mut store = use_store(|| HashMap::new());
store.insert(0, "value".to_string());
assert_eq!(store.get_unchecked(0).cloned(), "value".to_string());
Source§

impl<Lens, T> Store<T, Lens>

Source

pub fn index<Idx>( self, index: Idx, ) -> Store<<T as Index<Idx>>::Output, IndexWrite<Idx, Lens>>
where T: IndexMut<Idx> + 'static + IndexSelector<Idx>, Lens: Readable<Target = T> + 'static,

Index into the store, returning a store that allows access to the item at the given index. The new store will only update when the item at the index changes.

§Example
use dioxus_stores::*;
let store = use_store(|| vec![1, 2, 3]);
let indexed_store = store.index(1);
// The indexed store can access the store methods of the indexed store.
assert_eq!(indexed_store(), 2);
Source§

impl<Lens, T> Store<Option<T>, Lens>
where Lens: Readable<Target = Option<T>> + 'static, T: 'static,

Source

pub fn is_some(&self) -> bool

Checks if the Option is Some. This will only track the shallow state of the Option. It will only cause a re-run if the Option could change from None to Some or vice versa.

§Example
use dioxus_stores::*;
let store = use_store(|| Some(42));
assert!(store.is_some());
Source

pub fn is_some_and(&self, f: impl FnOnce(&T) -> bool) -> bool

Returns true if the option is Some and the closure returns true. This will always track the shallow state of the and will track the inner state of the enum if the enum is Some.

§Example
use dioxus_stores::*;
let store = use_store(|| Some(42));
assert!(store.is_some_and(|v| *v == 42));
Source

pub fn is_none(&self) -> bool

Checks if the Option is None. This will only track the shallow state of the Option. It will only cause a re-run if the Option could change from Some to None or vice versa.

§Example
use dioxus_stores::*;
let store = use_store(|| None::<i32>);
assert!(store.is_none());
Source

pub fn is_none_or(&self, f: impl FnOnce(&T) -> bool) -> bool

Returns true if the option is None or the closure returns true. This will always track the shallow state of the and will track the inner state of the enum if the enum is Some.

§Example
use dioxus_stores::*;
let store = use_store(|| Some(42));
assert!(store.is_none_or(|v| *v == 42));
Source

pub fn transpose( self, ) -> Option<Store<T, MappedMutSignal<T, Lens, fn(&<Lens as Readable>::Target) -> &T, fn(&mut <Lens as Readable>::Target) -> &mut T>>>

Transpose the Store<Option<T>> into a Option<Store<T>>. This will only track the shallow state of the Option. It will only cause a re-run if the Option could change from None to Some or vice versa.

§Example
use dioxus_stores::*;
let store = use_store(|| Some(42));
let transposed = store.transpose();
match transposed {
    Some(inner_store) => assert_eq!(inner_store(), 42),
    None => panic!("Expected Some"),
}
Source

pub fn unwrap( self, ) -> Store<T, MappedMutSignal<T, Lens, fn(&<Lens as Readable>::Target) -> &T, fn(&mut <Lens as Readable>::Target) -> &mut T>>

Unwraps the Option and returns a Store<T>. This will only track the shallow state of the Option. It will only cause a re-run if the Option could change from None to Some or vice versa.

§Example
use dioxus_stores::*;
let store = use_store(|| Some(42));
let unwrapped = store.unwrap();
assert_eq!(unwrapped(), 42);
Source

pub fn expect( self, msg: &str, ) -> Store<T, MappedMutSignal<T, Lens, fn(&<Lens as Readable>::Target) -> &T, fn(&mut <Lens as Readable>::Target) -> &mut T>>

Expects the Option to be Some and returns a Store<T>. If the value is None, this will panic with msg. This will only track the shallow state of the Option. It will only cause a re-run if the Option could change from None to Some or vice versa.

§Example
use dioxus_stores::*;
let store = use_store(|| Some(42));
let unwrapped = store.expect("the answer to life the universe and everything");
assert_eq!(unwrapped(), 42);
Source

pub fn as_slice( self, ) -> Store<[T], MappedMutSignal<[T], Lens, fn(&<Lens as Readable>::Target) -> &[T], fn(&mut <Lens as Readable>::Target) -> &mut [T]>>

Returns a slice of the contained value, or an empty slice. This will not subscribe to any part of the store.

§Example
use dioxus::prelude::*;
use dioxus_stores::*;
let store = use_store(|| Some(42));
let slice = store.as_slice();
assert_eq!(&*slice.read(), [42]);
Source

pub fn as_deref( self, ) -> Option<Store<<T as Deref>::Target, MappedMutSignal<<T as Deref>::Target, Lens, fn(&<Lens as Readable>::Target) -> &<T as Deref>::Target, fn(&mut <Lens as Readable>::Target) -> &mut <T as Deref>::Target>>>
where T: DerefMut,

Transpose the store then coerce the contents of the Option with deref. This will only track the shallow state of the Option. It will only cause a re-run if the Option could change from None to Some or vice versa.

§Example
use dioxus_stores::*;
let store = use_store(|| Some(Box::new(42)));
let derefed = store.as_deref().unwrap();
assert_eq!(derefed(), 42);
Source

pub fn filter( self, f: impl FnOnce(&T) -> bool, ) -> Option<Store<T, MappedMutSignal<T, Lens, fn(&<Lens as Readable>::Target) -> &T, fn(&mut <Lens as Readable>::Target) -> &mut T>>>

Transpose the store then filter the contents of the Option with a closure. This will always track the shallow state of the and will track the inner state of the enum if the enum is Some.

§Example
use dioxus_stores::*;
let store = use_store(|| Some(42));
let option = store.filter(|&v| v > 40);
let value = option.unwrap();
assert_eq!(value(), 42);
Source

pub fn inspect(self, f: impl FnOnce(&T)) -> Store<Option<T>, Lens>

Call the function with a reference to the inner value if it is Some. This will always track the shallow state of the and will track the inner state of the enum if the enum is Some.

§Example
use dioxus_stores::*;
let store = use_store(|| Some(42)).inspect(|v| println!("{v}"));
Source§

impl<Lens, T, E> Store<Result<T, E>, Lens>
where Lens: Readable<Target = Result<T, E>> + 'static, T: 'static, E: 'static,

Source

pub fn is_ok(&self) -> bool

Checks if the Result is Ok. This will only track the shallow state of the Result. It will only cause a re-run if the Result could change from Err to Ok or vice versa.

§Example
use dioxus_stores::*;
let store = use_store(|| Ok::<u32, ()>(42));
assert!(store.is_ok());
Source

pub fn is_ok_and(&self, f: impl FnOnce(&T) -> bool) -> bool

Returns true if the result is Ok and the closure returns true. This will always track the shallow state of the and will track the inner state of the enum if the enum is Ok.

§Example
use dioxus_stores::*;
let store = use_store(|| Ok::<u32, ()>(42));
assert!(store.is_ok_and(|v| *v == 42));
Source

pub fn is_err(&self) -> bool

Checks if the Result is Err. This will only track the shallow state of the Result. It will only cause a re-run if the Result could change from Ok to Err or vice versa.

§Example
use dioxus_stores::*;
let store = use_store(|| Err::<(), u32>(42));
assert!(store.is_err());
Source

pub fn is_err_and(&self, f: impl FnOnce(&E) -> bool) -> bool

Returns true if the result is Err and the closure returns true. This will always track the shallow state of the and will track the inner state of the enum if the enum is Err.

§Example
use dioxus_stores::*;
let store = use_store(|| Err::<(), u32>(42));
assert!(store.is_err_and(|v| *v == 42));
Source

pub fn ok( self, ) -> Option<Store<T, MappedMutSignal<T, Lens, fn(&<Lens as Readable>::Target) -> &T, fn(&mut <Lens as Readable>::Target) -> &mut T>>>

Converts Store<Result<T, E>> into Option<Store<T>>, discarding the error if present. This will only track the shallow state of the Result. It will only cause a re-run if the Result could change from Err to Ok or vice versa.

§Example
use dioxus_stores::*;
let store = use_store(|| Ok::<u32, ()>(42));
match store.ok() {
    Some(ok_store) => assert_eq!(ok_store(), 42),
    None => panic!("Expected Ok"),
}
Source

pub fn err( self, ) -> Option<Store<E, MappedMutSignal<E, Lens, fn(&<Lens as Readable>::Target) -> &E, fn(&mut <Lens as Readable>::Target) -> &mut E>>>
where Lens: Writable<Target = Result<T, E>> + 'static,

Converts Store<Result<T, E>> into Option<Store<E>>, discarding the success if present. This will only track the shallow state of the Result. It will only cause a re-run if the Result could change from Ok to Err or vice versa.

§Example
use dioxus_stores::*;
let store = use_store(|| Err::<(), u32>(42));
match store.err() {
    Some(err_store) => assert_eq!(err_store(), 42),
    None => panic!("Expected Err"),
}
Source

pub fn transpose( self, ) -> Result<Store<T, MappedMutSignal<T, Lens, fn(&<Lens as Readable>::Target) -> &T, fn(&mut <Lens as Readable>::Target) -> &mut T>>, Store<E, MappedMutSignal<E, Lens, fn(&<Lens as Readable>::Target) -> &E, fn(&mut <Lens as Readable>::Target) -> &mut E>>>
where Lens: Writable<Target = Result<T, E>> + 'static,

Transposes the Store<Result<T, E>> into a Result<Store<T>, Store<E>>. This will only track the shallow state of the Result. It will only cause a re-run if the Result could change from Err to Ok or vice versa.

§Example
use dioxus_stores::*;
let store = use_store(|| Ok::<u32, ()>(42));
match store.transpose() {
    Ok(ok_store) => assert_eq!(ok_store(), 42),
    Err(err_store) => assert_eq!(err_store(), ()),
}
Source

pub fn unwrap( self, ) -> Store<T, MappedMutSignal<T, Lens, fn(&<Lens as Readable>::Target) -> &T, fn(&mut <Lens as Readable>::Target) -> &mut T>>
where Lens: Writable<Target = Result<T, E>> + 'static, E: Debug,

Unwraps the Result and returns a Store<T>. This will only track the shallow state of the Result. It will only cause a re-run if the Result could change from Err to Ok or vice versa.

§Example
use dioxus_stores::*;
let store = use_store(|| Ok::<u32, ()>(42));
let unwrapped = store.unwrap();
assert_eq!(unwrapped(), 42);
Source

pub fn expect( self, msg: &str, ) -> Store<T, MappedMutSignal<T, Lens, fn(&<Lens as Readable>::Target) -> &T, fn(&mut <Lens as Readable>::Target) -> &mut T>>
where Lens: Writable<Target = Result<T, E>> + 'static, E: Debug,

Expects the Result to be Ok and returns a Store<T>. If the value is Err, this will panic with msg. This will only track the shallow state of the Result. It will only cause a re-run if the Result could change from Err to Ok or vice versa.

§Example
use dioxus_stores::*;
let store = use_store(|| Ok::<u32, ()>(42));
let unwrapped = store.expect("Expected Ok");
assert_eq!(unwrapped(), 42);
Source

pub fn unwrap_err( self, ) -> Store<E, MappedMutSignal<E, Lens, fn(&<Lens as Readable>::Target) -> &E, fn(&mut <Lens as Readable>::Target) -> &mut E>>
where Lens: Writable<Target = Result<T, E>> + 'static, T: Debug,

Unwraps the error variant of the Result. This will only track the shallow state of the Result. It will only cause a re-run if the Result could change from Ok to Err or vice versa.

§Example
use dioxus_stores::*;
let store = use_store(|| Err::<(), u32>(42));
let unwrapped_err = store.unwrap_err();
assert_eq!(unwrapped_err(), 42);
Source

pub fn expect_err( self, msg: &str, ) -> Store<E, MappedMutSignal<E, Lens, fn(&<Lens as Readable>::Target) -> &E, fn(&mut <Lens as Readable>::Target) -> &mut E>>
where Lens: Writable<Target = Result<T, E>> + 'static, T: Debug,

Expects the Result to be Err and returns a Store<E>. If the value is Ok, this will panic with msg. This will only track the shallow state of the Result. It will only cause a re-run if the Result could change from Ok to Err or vice versa.

§Example
use dioxus_stores::*;
let store = use_store(|| Err::<(), u32>(42));
let unwrapped_err = store.expect_err("Expected Err");
assert_eq!(unwrapped_err(), 42);
Source

pub fn inspect(self, f: impl FnOnce(&T)) -> Store<Result<T, E>, Lens>
where Lens: Writable<Target = Result<T, E>> + 'static,

Call the function with a reference to the inner value if it is Ok. This will always track the shallow state of the and will track the inner state of the enum if the enum is Ok.

§Example
use dioxus_stores::*;
let store = use_store(|| Ok::<u32, ()>(42)).inspect(|v| println!("{v}"));
Source

pub fn inspect_err(self, f: impl FnOnce(&E)) -> Store<Result<T, E>, Lens>
where Lens: Writable<Target = Result<T, E>> + 'static,

Call the function with a mutable reference to the inner value if it is Err. This will always track the shallow state of the Result and will track the inner state of the enum if the enum is Err.

§Example
use dioxus_stores::*;
let store = use_store(|| Err::<(), u32>(42)).inspect_err(|v| println!("{v}"));
Source

pub fn as_deref( self, ) -> Result<Store<<T as Deref>::Target, MappedMutSignal<<T as Deref>::Target, Lens, fn(&<Lens as Readable>::Target) -> &<T as Deref>::Target, fn(&mut <Lens as Readable>::Target) -> &mut <T as Deref>::Target>>, Store<E, MappedMutSignal<E, Lens, fn(&<Lens as Readable>::Target) -> &E, fn(&mut <Lens as Readable>::Target) -> &mut E>>>
where Lens: Writable<Target = Result<T, E>> + 'static, T: DerefMut,

Transpose the store then coerce the contents of the Result with deref. This will only track the shallow state of the Result. It will only cause a re-run if the Result could change from Err to Ok or vice versa.

§Example
use dioxus_stores::*;
let store = use_store(|| Ok::<Box<u32>, ()>(Box::new(42)));
let derefed = store.as_deref().unwrap();
assert_eq!(derefed(), 42);
Source§

impl<Lens, I> Store<Vec<I>, Lens>
where Lens: Readable<Target = Vec<I>> + 'static, I: 'static,

Source

pub fn len(&self) -> usize

Returns the length of the slice. This will only track the shallow state of the slice. It will only cause a re-run if the length of the slice could change.

§Example
use dioxus_stores::*;
let store = use_store(|| vec![1, 2, 3]);
assert_eq!(store.len(), 3);
Source

pub fn is_empty(&self) -> bool

Checks if the slice is empty. This will only track the shallow state of the slice. It will only cause a re-run if the length of the slice could change.

§Example
use dioxus_stores::*;
let store = use_store(|| vec![1, 2, 3]);
assert!(!store.is_empty());
Source

pub fn iter( &self, ) -> impl ExactSizeIterator + DoubleEndedIterator + FusedIterator
where Lens: Clone,

Returns an iterator over the items in the slice. This will only track the shallow state of the slice. It will only cause a re-run if the length of the slice could change.

§Example
use dioxus_stores::*;
let store = use_store(|| vec![1, 2, 3]);
for item in store.iter() {
    println!("{}", item);
}
Source

pub fn get(&self, index: usize) -> Option<Store<I, IndexWrite<usize, Lens>>>
where Lens: Clone,

Try to get an item from slice. This will only track the shallow state of the slice. It will only cause a re-run if the length of the slice could change. The new store will only update when the item at the index changes.

§Example
use dioxus_stores::*;
let store = use_store(|| vec![1, 2, 3]);
let indexed_store = store.get(1).unwrap();
// The indexed store can access the store methods of the indexed store.
assert_eq!(indexed_store(), 2);
Source§

impl<Lens, T> Store<Vec<T>, Lens>
where Lens: Writable<Target = Vec<T>> + 'static, T: 'static,

Source

pub fn push(&mut self, value: T)

Pushes an item to the end of the vector. This will only mark the length of the vector as dirty.

§Example
use dioxus_stores::*;
let mut store = use_store(|| vec![1, 2, 3]);
store.push(4);
Source

pub fn remove(&mut self, index: usize) -> T

Removes an item from the vector at the specified index and returns it. This will mark items after the index and the length of the vector as dirty.

§Example
use dioxus_stores::*;
let mut store = use_store(|| vec![1, 2, 3]);
let removed = store.remove(1);
assert_eq!(removed, 2);
Source

pub fn insert(&mut self, index: usize, value: T)

Inserts an item at the specified index in the vector. This will mark items at and after the index and the length of the vector as dirty.

§Example
use dioxus_stores::*;
let mut store = use_store(|| vec![1, 2, 3]);
store.insert(1, 4);
Source

pub fn clear(&mut self)

Clears the vector, marking it as dirty.

§Example
use dioxus_stores::*;
let mut store = use_store(|| vec![1, 2, 3]);
store.clear();
Source

pub fn retain(&mut self, f: impl FnMut(&T) -> bool)

Retains only the elements specified by the predicate. This will only mark the length of the vector and items after the first removed item as dirty.

§Example
use dioxus_stores::*;
let mut store = use_store(|| vec![1, 2, 3, 4, 5]);
store.retain(|&x| x % 2 == 0);
assert_eq!(store.len(), 2);
Source§

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

Source

pub fn new_maybe_sync(value: T) -> Store<T, CopyValue<T, S>>

Creates a new Store that might be sync. This allocates memory in the current scope, so this should only be called inside of an initialization closure like the closure passed to use_hook.

Source§

impl<T> Store<T>
where T: 'static,

Source

pub fn new(value: T) -> Store<T>

Creates a new Store. This allocates memory in the current scope, so this should only be called inside of an initialization closure like the closure passed to use_hook.

Source§

impl<T, Lens> Store<T, Lens>
where T: ?Sized,

Source

pub fn selector(&self) -> &SelectorScope<Lens>

Get the underlying selector for this store. The selector provides low level access to the lazy tracking system of the store. This can be useful to create selectors for custom data structures in libraries. For most applications the selectors generated by the Store macro provide all the functionality you need.

Source

pub fn into_selector(self) -> SelectorScope<Lens>

Convert the store into the underlying selector

Trait Implementations§

Source§

impl<T, Lens> Add<T> for Store<T, Lens>
where T: Add<Output = T> + Copy + 'static, Lens: Writable<Target = T>,

Source§

type Output = T

The resulting type after applying the + operator.
Source§

fn add(self, rhs: T) -> <Store<T, Lens> as Add<T>>::Output

Performs the + operation. Read more
Source§

impl<T, Lens> AddAssign<T> for Store<T, Lens>
where T: Add<Output = T> + Copy + 'static, Lens: Writable<Target = T>,

Source§

fn add_assign(&mut self, rhs: T)

Performs the += operation. Read more
Source§

impl<T, Lens> Clone for Store<T, Lens>
where Lens: Clone, T: ?Sized,

Source§

fn clone(&self) -> Store<T, Lens>

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T, Lens> Debug for Store<T, Lens>
where T: Debug + 'static, Lens: Readable<Target = T>,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<T, Lens> Deref for Store<T, Lens>
where Store<T, Lens>: Readable<Target = T> + 'static, T: Clone + 'static,

Source§

type Target = dyn Fn() -> T

The resulting type after dereferencing.
Source§

fn deref(&self) -> &<Store<T, Lens> as Deref>::Target

Dereferences the value.
Source§

impl<T, Lens> Display for Store<T, Lens>
where T: Display + 'static, Lens: Readable<Target = T>,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<T, Lens> Div<T> for Store<T, Lens>
where T: Div<Output = T> + Copy + 'static, Lens: Writable<Target = T>,

Source§

type Output = T

The resulting type after applying the / operator.
Source§

fn div(self, rhs: T) -> <Store<T, Lens> as Div<T>>::Output

Performs the / operation. Read more
Source§

impl<T, Lens> DivAssign<T> for Store<T, Lens>
where T: Div<Output = T> + Copy + 'static, Lens: Writable<Target = T>,

Source§

fn div_assign(&mut self, rhs: T)

Performs the /= operation. Read more
Source§

impl<T, Lens> From<SelectorScope<Lens>> for Store<T, Lens>
where T: ?Sized,

Source§

fn from(selector: SelectorScope<Lens>) -> Store<T, Lens>

Converts to this type from the input type.
Source§

impl<T, S> From<Store<T, CopyValue<T, S>>> for Store<T, ReadSignal<T, S>>
where T: 'static, S: BoxedSignalStorage<T> + CreateBoxedSignalStorage<CopyValue<T, S>> + Storage<T>,

Source§

fn from(value: Store<T, CopyValue<T, S>>) -> Store<T, ReadSignal<T, S>>

Converts to this type from the input type.
Source§

impl<T, S> From<Store<T, CopyValue<T, S>>> for Store<T, WriteSignal<T, S>>
where T: 'static, S: BoxedSignalStorage<T> + CreateBoxedSignalStorage<CopyValue<T, S>> + Storage<T>,

Source§

fn from(value: Store<T, CopyValue<T, S>>) -> Store<T, WriteSignal<T, S>>

Converts to this type from the input type.
Source§

impl<Idx, T, Write> From<Store<T, IndexWrite<Idx, Write>>> for Store<T>
where Write: Writable<Storage = UnsyncStorage> + 'static, <Write as Writable>::WriteMetadata: 'static, <Write as Readable>::Target: IndexMut<Idx, Output = T> + 'static, Idx: Clone + 'static, T: 'static,

Source§

fn from(value: Store<T, IndexWrite<Idx, Write>>) -> Store<T>

Converts to this type from the input type.
Source§

impl<Idx, T, Write> From<Store<T, IndexWrite<Idx, Write>>> for Store<T, ReadSignal<T>>
where Write: Readable<Storage = UnsyncStorage> + 'static, <Write as Readable>::Target: Index<Idx, Output = T> + 'static, Idx: Clone + 'static, T: 'static,

Source§

fn from(value: Store<T, IndexWrite<Idx, Write>>) -> Store<T, ReadSignal<T>>

Converts to this type from the input type.
Source§

impl<__F, __FMut, T, S, Lens> From<Store<T, MappedMutSignal<T, Lens, __F, __FMut>>> for Store<T, ReadSignal<T, S>>
where Lens: Writable<Storage = S> + 'static, __F: Fn(&<Lens as Readable>::Target) -> &T + 'static, __FMut: Fn(&mut <Lens as Readable>::Target) -> &mut T + 'static, S: BoxedSignalStorage<T> + CreateBoxedSignalStorage<MappedMutSignal<T, Lens, __F, __FMut>>, T: 'static + ?Sized,

Source§

fn from( value: Store<T, MappedMutSignal<T, Lens, __F, __FMut>>, ) -> Store<T, ReadSignal<T, S>>

Converts to this type from the input type.
Source§

impl<__F, __FMut, T, S, Lens> From<Store<T, MappedMutSignal<T, Lens, __F, __FMut>>> for Store<T, WriteSignal<T, S>>
where Lens: Writable<Storage = S> + 'static, __F: Fn(&<Lens as Readable>::Target) -> &T + 'static, __FMut: Fn(&mut <Lens as Readable>::Target) -> &mut T + 'static, S: BoxedSignalStorage<T> + CreateBoxedSignalStorage<MappedMutSignal<T, Lens, __F, __FMut>>, T: 'static + ?Sized,

Source§

fn from( value: Store<T, MappedMutSignal<T, Lens, __F, __FMut>>, ) -> Store<T, WriteSignal<T, S>>

Converts to this type from the input type.
Source§

impl<T, S> From<Store<T, WriteSignal<T, S>>> for Store<T, ReadSignal<T, S>>
where T: 'static + ?Sized, S: BoxedSignalStorage<T> + CreateBoxedSignalStorage<WriteSignal<T, S>>,

Source§

fn from(value: Store<T, WriteSignal<T, S>>) -> Store<T, ReadSignal<T, S>>

Converts to this type from the input type.
Source§

impl<Index, Write, K, V> From<Store<V, GetWrite<Index, Write>>> for Store<V>
where <Write as Writable>::WriteMetadata: 'static, Write: Writable<Target = BTreeMap<K, V>, Storage = UnsyncStorage> + 'static, Index: Ord + 'static, K: Borrow<Index> + Ord + 'static, V: 'static,

Source§

fn from(value: Store<V, GetWrite<Index, Write>>) -> Store<V>

Converts to this type from the input type.
Source§

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

Source§

fn from(value: Store<V, GetWrite<Index, Write>>) -> Store<V>

Converts to this type from the input type.
Source§

impl<Index, Write, K, V> From<Store<V, GetWrite<Index, Write>>> for Store<V, ReadSignal<V>>
where Write: Readable<Target = BTreeMap<K, V>, Storage = UnsyncStorage> + 'static, Index: Ord + 'static, K: Borrow<Index> + Ord + 'static, V: 'static,

Source§

fn from(value: Store<V, GetWrite<Index, Write>>) -> Store<V, ReadSignal<V>>

Converts to this type from the input type.
Source§

impl<Index, Write, K, V, St> From<Store<V, GetWrite<Index, Write>>> for Store<V, ReadSignal<V>>
where Write: Readable<Target = HashMap<K, V, St>, Storage = UnsyncStorage> + 'static, Index: Hash + Eq + 'static, K: Borrow<Index> + Eq + Hash + 'static, St: BuildHasher + 'static, V: 'static,

Source§

fn from(value: Store<V, GetWrite<Index, Write>>) -> Store<V, ReadSignal<V>>

Converts to this type from the input type.
Source§

impl<T> InitializeFromFunction<T> for Store<T>
where T: 'static,

Source§

fn initialize_from_function(f: fn() -> T) -> Store<T>

Create an instance of this type from an initialization function
Source§

impl<T, Lens> IntoAttributeValue for Store<T, Lens>
where Store<T, Lens>: Readable<Target = T>, T: Clone + IntoAttributeValue + 'static,

Source§

fn into_value(self) -> AttributeValue

Convert into an attribute value
Source§

impl<T, Lens> IntoDynNode for Store<T, Lens>
where Store<T, Lens>: Readable<Target = T>, T: Clone + IntoDynNode + 'static,

Source§

fn into_dyn_node(self) -> DynamicNode

Consume this item and produce a DynamicNode
Source§

impl<T, Lens> Mul<T> for Store<T, Lens>
where T: Mul<Output = T> + Copy + 'static, Lens: Writable<Target = T>,

Source§

type Output = T

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: T) -> <Store<T, Lens> as Mul<T>>::Output

Performs the * operation. Read more
Source§

impl<T, Lens> MulAssign<T> for Store<T, Lens>
where T: Mul<Output = T> + Copy + 'static, Lens: Writable<Target = T>,

Source§

fn mul_assign(&mut self, rhs: T)

Performs the *= operation. Read more
Source§

impl<T, Lens> PartialEq<T> for Store<T, Lens>
where T: PartialEq + 'static, Lens: Readable<Target = T>,

Source§

fn eq(&self, other: &T) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T, Lens> PartialEq for Store<T, Lens>
where Lens: PartialEq, T: ?Sized,

Source§

fn eq(&self, other: &Store<T, Lens>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

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

Source§

type Storage = <Lens as Readable>::Storage

The type of the storage this readable uses.
Source§

type Target = T

The target type of the reference.
Source§

fn try_read_unchecked( &self, ) -> Result<<<Store<T, Lens> as Readable>::Storage as AnyStorage>::Ref<'static, <Store<T, Lens> as Readable>::Target>, BorrowError>

Try to get a reference to the value without checking the lifetime. This will subscribe the current scope to the signal. Read more
Source§

fn try_peek_unchecked( &self, ) -> Result<<<Store<T, Lens> as Readable>::Storage as AnyStorage>::Ref<'static, <Store<T, Lens> as Readable>::Target>, BorrowError>

Try to peek the current value of the signal without subscribing to updates. If the value has been dropped, this will return an error. Read more
Source§

fn subscribers(&self) -> Subscribers

Get the underlying subscriber list for this readable. This is used to track when the value changes and notify subscribers.
Source§

impl<T, Lens> Sub<T> for Store<T, Lens>
where T: Sub<Output = T> + Copy + 'static, Lens: Writable<Target = T>,

Source§

type Output = T

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: T) -> <Store<T, Lens> as Sub<T>>::Output

Performs the - operation. Read more
Source§

impl<T, Lens> SubAssign<T> for Store<T, Lens>
where T: Sub<Output = T> + Copy + 'static, Lens: Writable<Target = T>,

Source§

fn sub_assign(&mut self, rhs: T)

Performs the -= operation. Read more
Source§

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

Source§

type WriteMetadata = <Lens as Writable>::WriteMetadata

Additional data associated with the write reference.
Source§

fn try_write_unchecked( &self, ) -> Result<WriteLock<'static, <Store<T, Lens> as Readable>::Target, <Store<T, Lens> as Readable>::Storage, <Store<T, Lens> as Writable>::WriteMetadata>, BorrowMutError>

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

impl<T, Lens> Copy for Store<T, Lens>
where Lens: Copy, T: ?Sized,

Auto Trait Implementations§

§

impl<T, Lens> Freeze for Store<T, Lens>
where Lens: Freeze, T: ?Sized,

§

impl<T, Lens = WriteSignal<T>> !RefUnwindSafe for Store<T, Lens>

§

impl<T, Lens> Send for Store<T, Lens>
where Lens: Send, T: Send + ?Sized,

§

impl<T, Lens> Sync for Store<T, Lens>
where Lens: Sync, T: Sync + ?Sized,

§

impl<T, Lens> Unpin for Store<T, Lens>
where Lens: Unpin, T: ?Sized,

§

impl<T, Lens = WriteSignal<T>> !UnwindSafe for Store<T, Lens>

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> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> InitializeFromFunction<T> for T

Source§

fn initialize_from_function(f: fn() -> T) -> T

Create an instance of this type from an initialization function
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> MaybeBoxed<Box<T>> for T

Source§

fn maybe_boxed(self) -> Box<T>

Convert
Source§

impl<T> MaybeBoxed<T> for T

Source§

fn maybe_boxed(self) -> T

Convert
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<R> ReadableBoxExt for R
where R: Readable<Storage = UnsyncStorage> + ?Sized,

Source§

fn boxed(self) -> ReadSignal<Self::Target>
where Self: Sized + 'static,

Box the readable value into a trait object. This is useful for passing around readable values without knowing their concrete type.
Source§

impl<R> ReadableExt for R
where R: Readable + ?Sized,

Source§

fn read(&self) -> <Self::Storage as AnyStorage>::Ref<'_, Self::Target>
where Self::Target: 'static,

Get the current value of the state. If this is a signal, this will subscribe the current scope to the signal. If the value has been dropped, this will panic. Calling this on a Signal is the same as using the signal() syntax to read and subscribe to its value
Source§

fn try_read( &self, ) -> Result<<Self::Storage as AnyStorage>::Ref<'_, Self::Target>, BorrowError>
where Self::Target: 'static,

Try to get the current value of the state. If this is a signal, this will subscribe the current scope to the signal.
Source§

fn read_unchecked( &self, ) -> <Self::Storage as AnyStorage>::Ref<'static, Self::Target>
where Self::Target: 'static,

Get a reference to the value without checking the lifetime. This will subscribe the current scope to the signal. Read more
Source§

fn peek(&self) -> <Self::Storage as AnyStorage>::Ref<'_, Self::Target>
where Self::Target: 'static,

Get the current value of the state without subscribing to updates. If the value has been dropped, this will panic. Read more
Source§

fn try_peek( &self, ) -> Result<<Self::Storage as AnyStorage>::Ref<'_, Self::Target>, BorrowError>
where Self::Target: 'static,

Try to peek the current value of the signal without subscribing to updates. If the value has been dropped, this will return an error.
Source§

fn peek_unchecked( &self, ) -> <Self::Storage as AnyStorage>::Ref<'static, Self::Target>
where Self::Target: 'static,

Get the current value of the signal without checking the lifetime. Unlike read, this will not subscribe the current scope to the signal which can cause parts of your UI to not update. Read more
Source§

fn map<F, O>(self, f: F) -> MappedSignal<O, Self, F>
where Self: Sized + Clone, F: Fn(&Self::Target) -> &O,

Map the references of the readable value to a new type. This lets you provide a view into the readable value without creating a new signal or cloning the value. Read more
Source§

fn cloned(&self) -> Self::Target
where Self::Target: Clone + 'static,

Clone the inner value and return it. If the value has been dropped, this will panic.
Source§

fn with<O>(&self, f: impl FnOnce(&Self::Target) -> O) -> O
where Self::Target: 'static,

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

fn with_peek<O>(&self, f: impl FnOnce(&Self::Target) -> O) -> O
where Self::Target: 'static,

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

fn index<I>( &self, index: I, ) -> <Self::Storage as AnyStorage>::Ref<'_, <Self::Target as Index<I>>::Output>
where Self::Target: Index<I> + 'static,

Index into the inner value and return a reference to the result. If the value has been dropped or the index is invalid, this will panic.
Source§

impl<K, V, H, R> ReadableHashMapExt<K, V, H> for R
where K: 'static, V: 'static, H: 'static, R: Readable<Target = HashMap<K, V, H>>,

Source§

fn is_empty(&self) -> bool

Check if the hashmap is empty.
Source§

fn len(&self) -> usize

Get the length of the hashmap.
Source§

fn capacity(&self) -> usize

Get the capacity of the hashmap.
Source§

fn get(&self, key: &K) -> Option<<Self::Storage as AnyStorage>::Ref<'_, V>>
where K: Hash + Eq, H: BuildHasher,

Get the value for the given key.
Source§

fn contains_key(&self, key: &K) -> bool
where K: Hash + Eq, H: BuildHasher,

Check if the hashmap contains the given key.
Source§

impl<V, H, R> ReadableHashSetExt<V, H> for R
where V: 'static, H: 'static, R: Readable<Target = HashSet<V, H>>,

Source§

fn is_empty(&self) -> bool

Check if the hashset is empty.
Source§

fn len(&self) -> usize

Get the length of the hashset.
Source§

fn capacity(&self) -> usize

Get the capacity of the hashset.
Source§

fn contains(&self, value: &V) -> bool
where V: Hash + Eq, H: BuildHasher,

Check if the hashset contains the given value.
Source§

impl<T, R> ReadableOptionExt<T> for R
where R: Readable<Target = Option<T>>,

Source§

fn unwrap(&self) -> T
where T: Clone + 'static,

Unwraps the inner value and clones it.
Source§

fn as_ref(&self) -> Option<<Self::Storage as AnyStorage>::Ref<'_, T>>
where T: 'static,

Attempts to read the inner value of the Option.
Source§

impl<T, E, R> ReadableResultExt<T, E> for R
where R: Readable<Target = Result<T, E>>,

Source§

fn unwrap(&self) -> T
where T: Clone + 'static, E: 'static,

Unwraps the inner value and clones it.
Source§

fn as_ref( &self, ) -> Result<<Self::Storage as AnyStorage>::Ref<'_, T>, <Self::Storage as AnyStorage>::Ref<'_, E>>
where T: 'static, E: 'static,

Attempts to read the inner value of the Option.
Source§

impl<W> ReadableStringExt for W
where W: Readable<Target = String>,

Source§

fn capacity(&self) -> usize

Check the capacity of the string.
Source§

impl<T, R> ReadableVecExt<T> for R
where R: Readable<Target = Vec<T>>,

Source§

fn len(&self) -> usize
where T: 'static,

Returns the length of the inner vector.
Source§

fn is_empty(&self) -> bool
where T: 'static,

Returns true if the inner vector is empty.
Source§

fn first(&self) -> Option<<Self::Storage as AnyStorage>::Ref<'_, T>>
where T: 'static,

Get the first element of the inner vector.
Source§

fn last(&self) -> Option<<Self::Storage as AnyStorage>::Ref<'_, T>>
where T: 'static,

Get the last element of the inner vector.
Source§

fn get(&self, index: usize) -> Option<<Self::Storage as AnyStorage>::Ref<'_, T>>
where T: 'static,

Get the element at the given index of the inner vector.
Source§

fn iter(&self) -> ReadableValueIterator<'_, Self>
where Self: Sized,

Get an iterator over the values of the inner vector.
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<Ret> SpawnIfAsync<(), Ret> for Ret

Source§

fn spawn(self) -> Ret

Spawn the value into the dioxus runtime if it is an async block
Source§

impl<T, O> SuperFrom<T> for O
where O: From<T>,

Source§

fn super_from(input: T) -> O

Convert from a type to another type.
Source§

impl<T, O, M> SuperInto<O, M> for T
where O: SuperFrom<T, M>,

Source§

fn super_into(self) -> O

Convert from a type to another type.
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> ToSmolStr for T
where T: Display + ?Sized,

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T> ToStringFallible for T
where T: Display,

Source§

fn try_to_string(&self) -> Result<String, TryReserveError>

ToString::to_string, but without panic on OOM.

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.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> WritableBoxedExt for T
where T: Writable<Storage = UnsyncStorage> + 'static,

Source§

fn boxed_mut(self) -> WriteSignal<<T as Readable>::Target>

Box the writable value into a trait object. This is useful for passing around writable values without knowing their concrete type.
Source§

impl<W> WritableExt for W
where W: Writable + ?Sized,

Source§

fn write( &mut self, ) -> WriteLock<'_, Self::Target, Self::Storage, Self::WriteMetadata>
where Self::Target: 'static,

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

fn try_write( &mut self, ) -> Result<WriteLock<'_, Self::Target, Self::Storage, Self::WriteMetadata>, BorrowMutError>
where Self::Target: 'static,

Try to get a mutable reference to the value.
Source§

fn write_unchecked( &self, ) -> WriteLock<'static, Self::Target, Self::Storage, Self::WriteMetadata>
where Self::Target: 'static,

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

fn map_mut<O, F, FMut>( self, f: F, f_mut: FMut, ) -> MappedMutSignal<O, Self, F, FMut>
where Self: Sized, F: Fn(&Self::Target) -> &O, FMut: Fn(&mut Self::Target) -> &mut O, O: ?Sized,

Map the references and mutable references of the writable value to a new type. This lets you provide a view into the writable value without creating a new signal or cloning the value. Read more
Source§

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

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 + 'static,

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 + 'static,

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

fn index_mut<I>( &mut self, index: I, ) -> WriteLock<'_, <Self::Target as Index<I>>::Output, Self::Storage, Self::WriteMetadata>
where Self::Target: IndexMut<I> + 'static,

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

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

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 + 'static,

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

impl<K, V, H, R> WritableHashMapExt<K, V, H> for R
where K: 'static, V: 'static, H: 'static, R: Writable<Target = HashMap<K, V, H>>,

Source§

fn clear(&mut self)

Clears the map, removing all key-value pairs.
Source§

fn retain(&mut self, f: impl FnMut(&K, &mut V) -> bool)

Retains only the key-value pairs that match the given predicate.
Source§

fn insert(&mut self, k: K, v: V) -> Option<V>
where K: Eq + Hash, H: BuildHasher,

Inserts a key-value pair into the map. If the key was already present, the old value is returned.
Source§

fn extend(&mut self, iter: impl IntoIterator<Item = (K, V)>)
where K: Eq + Hash, H: BuildHasher,

Extends the map with the key-value pairs from the given iterator.
Source§

fn remove(&mut self, k: &K) -> Option<V>
where K: Eq + Hash, H: BuildHasher,

Removes a key from the map, returning the value at the key if the key was previously in the map.
Source§

fn get_mut( &mut self, k: &K, ) -> Option<WriteLock<'_, V, Self::Storage, Self::WriteMetadata>>
where K: Eq + Hash, H: BuildHasher,

Get a mutable reference to the value at the given key.
Source§

impl<V, H, R> WritableHashSetExt<V, H> for R
where V: 'static, H: 'static, R: Writable<Target = HashSet<V, H>>,

Source§

fn clear(&mut self)

Clear the hash set.
Source§

fn retain(&mut self, f: impl FnMut(&V) -> bool)

Retain only the elements specified by the predicate.
Source§

fn insert(&mut self, k: V) -> bool
where V: Eq + Hash, H: BuildHasher,

Inserts a value into the set. Returns true if the value was not already present.
Source§

fn extend(&mut self, iter: impl IntoIterator<Item = V>)
where V: Eq + Hash, H: BuildHasher,

Extends the set with the values from the given iterator.
Source§

fn remove(&mut self, k: &V) -> bool
where V: Eq + Hash, H: BuildHasher,

Removes a value from the set. Returns true if the value was present.
Source§

impl<T, W> WritableOptionExt<T> for W
where W: Writable<Target = Option<T>>,

Source§

fn get_or_insert( &mut self, default: T, ) -> WriteLock<'_, T, Self::Storage, Self::WriteMetadata>
where T: 'static,

Gets the value out of the Option, or inserts the given value if the Option is empty.
Source§

fn get_or_insert_with( &mut self, default: impl FnOnce() -> T, ) -> WriteLock<'_, T, Self::Storage, Self::WriteMetadata>
where T: 'static,

Gets the value out of the Option, or inserts the value returned by the given function if the Option is empty.
Source§

fn as_mut( &mut self, ) -> Option<WriteLock<'_, T, Self::Storage, Self::WriteMetadata>>
where T: 'static,

Attempts to write the inner value of the Option.
Source§

impl<W> WritableStringExt for W
where W: Writable<Target = String>,

Source§

fn push_str(&mut self, s: &str)

Pushes a character to the end of the string.
Source§

fn push(&mut self, c: char)

Pushes a character to the end of the string.
Source§

fn pop(&mut self) -> Option<char>

Pops a character from the end of the string.
Source§

fn insert_str(&mut self, idx: usize, s: &str)

Inserts a string at the given index.
Source§

fn insert(&mut self, idx: usize, c: char)

Inserts a character at the given index.
Source§

fn remove(&mut self, idx: usize) -> char

Remove a character at the given index
Source§

fn replace_range(&mut self, range: impl RangeBounds<usize>, replace_with: &str)

Replace a range of the string with the given string.
Source§

fn clear(&mut self)

Clears the string, removing all characters.
Source§

fn extend(&mut self, iter: impl IntoIterator<Item = char>)

Extends the string with the given iterator of characters.
Source§

fn truncate(&mut self, len: usize)

Truncates the string to the given length.
Source§

fn split_off(&mut self, at: usize) -> String

Splits the string off at the given index, returning the tail as a new string.
Source§

impl<W, T> WritableVecExt<T> for W
where W: Writable<Target = Vec<T>>,

Source§

fn push(&mut self, value: T)
where T: 'static,

Pushes a new value to the end of the vector.
Source§

fn pop(&mut self) -> Option<T>
where T: 'static,

Pops the last value from the vector.
Source§

fn insert(&mut self, index: usize, value: T)
where T: 'static,

Inserts a new value at the given index.
Source§

fn remove(&mut self, index: usize) -> T
where T: 'static,

Removes the value at the given index.
Source§

fn clear(&mut self)
where T: 'static,

Clears the vector, removing all values.
Source§

fn extend(&mut self, iter: impl IntoIterator<Item = T>)
where T: 'static,

Extends the vector with the given iterator.
Source§

fn truncate(&mut self, len: usize)
where T: 'static,

Truncates the vector to the given length.
Source§

fn swap_remove(&mut self, index: usize) -> T
where T: 'static,

Swaps two values in the vector.
Source§

fn retain(&mut self, f: impl FnMut(&T) -> bool)
where T: 'static,

Retains only the values that match the given predicate.
Source§

fn split_off(&mut self, at: usize) -> Vec<T>
where T: 'static,

Splits the vector into two at the given index.
Source§

fn get_mut( &mut self, index: usize, ) -> Option<WriteLock<'_, T, Self::Storage, Self::WriteMetadata>>
where T: 'static,

Try to mutably get an element from the vector.
Source§

fn iter_mut(&mut self) -> WritableValueIterator<'_, Self>
where Self: Sized + Clone,

Gets an iterator over the values of the vector.
Source§

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

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,

Source§

impl<T> WasmNotSync for T
where T: Sync,