pub struct List<T>(/* private fields */);Expand description
A list of shareable values.
Using a List<T> rather than a Vec<T> allows components which use only one or two list items
to get updated only when the specific list items they use are changed.
use dioxus_shareables::{shareable, List, ListEntry};
shareable!(Numbers: List<usize> = [3, 5, 7].into_iter().collect());
#[allow(non_snake_case)]
fn ListNumbers(cx: Scope) -> Element {
let nums = Numbers.use_rw(&cx); // This component is updated when new items are added to or
// removed from the list, but not when the individual list
// items change.
let w = nums.clone();
cx.render(rsx! {
ul {
nums.read().iter().map(|n| rsx! { ListItem { num: n } })
}
button {
onclick: move |_| {
let mut w = w.write();
let sum = w.iter().map(|n| *n.share().read()).sum();
w.push(sum)
},
"Sum"
}
})
}
#[allow(non_snake_case)]
#[inline_props]
fn ListItem(cx: Scope, num: ListEntry<usize>) -> Element {
let num = num.use_rw(&cx); // This component is updated when this specific entry in the
// list is modified.
let w1 = num.clone();
let w2 = num.clone();
let num = num.read();
cx.render(rsx! {
li {
"{num}",
button { onclick: move |_| *w1.write() += 1, "+" }
button { onclick: move |_| *w2.write() -= 1, "-" }
}
})
}
List is a Vec internally, and the methods it implements therefore get their names and
behavior from Vec.
Implementations§
Source§impl<T> List<T>
impl<T> List<T>
Sourcepub fn append(&mut self, o: &mut Self)
pub fn append(&mut self, o: &mut Self)
See Vec::append
Sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
See Vec::capacity
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
See Vec::clear
Sourcepub fn dedup(&mut self)where
T: PartialEq,
pub fn dedup(&mut self)where
T: PartialEq,
See Vec::dedup
Sourcepub fn dedup_by_key<K: PartialEq, F: FnMut(&T) -> K>(&mut self, f: F)
pub fn dedup_by_key<K: PartialEq, F: FnMut(&T) -> K>(&mut self, f: F)
Sourcepub fn drain<R: RangeBounds<usize>>(&mut self, range: R) -> Drain<'_, T>where
T: 'static,
pub fn drain<R: RangeBounds<usize>>(&mut self, range: R) -> Drain<'_, T>where
T: 'static,
See Vec::drain
Sourcepub fn insert(&mut self, index: usize, element: T)
pub fn insert(&mut self, index: usize, element: T)
See Vec::insert
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
See Vec::is_empty
Sourcepub fn reserve(&mut self, additional: usize)
pub fn reserve(&mut self, additional: usize)
See Vec::reserve
Sourcepub fn reserve_exact(&mut self, additional: usize)
pub fn reserve_exact(&mut self, additional: usize)
Sourcepub fn resize(&mut self, new_len: usize, t: T)where
T: Clone,
pub fn resize(&mut self, new_len: usize, t: T)where
T: Clone,
See Vec::resize
Sourcepub fn resize_with<F: FnMut() -> T>(&mut self, new_len: usize, f: F)
pub fn resize_with<F: FnMut() -> T>(&mut self, new_len: usize, f: F)
See Vec::resize_with
Sourcepub fn retain_mut<F: FnMut(&mut ListEntry<T>) -> bool>(&mut self, f: F)where
T: 'static,
pub fn retain_mut<F: FnMut(&mut ListEntry<T>) -> bool>(&mut self, f: F)where
T: 'static,
See Vec::retain
Sourcepub fn shrink_to(&mut self, min_capacity: usize)
pub fn shrink_to(&mut self, min_capacity: usize)
See Vec::shrink_to
Sourcepub fn shrink_to_fit(&mut self)
pub fn shrink_to_fit(&mut self)
Sourcepub fn splice<'a, R: RangeBounds<usize>, I: 'a + IntoIterator<Item = T>>(
&'a mut self,
range: R,
replace_with: I,
) -> impl 'a + Iterator<Item = Shared<T, W>>where
T: 'static,
pub fn splice<'a, R: RangeBounds<usize>, I: 'a + IntoIterator<Item = T>>(
&'a mut self,
range: R,
replace_with: I,
) -> impl 'a + Iterator<Item = Shared<T, W>>where
T: 'static,
See Vec::splice
Sourcepub fn split_off(&mut self, at: usize) -> Self
pub fn split_off(&mut self, at: usize) -> Self
See Vec::split_off
Sourcepub fn swap_remove(&mut self, index: usize) -> Shared<T, W>
pub fn swap_remove(&mut self, index: usize) -> Shared<T, W>
See Vec::swap_remove
Sourcepub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError>
pub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError>
See [’Vec::try_reserve`]
Sourcepub fn try_reserve_exact(
&mut self,
additional: usize,
) -> Result<(), TryReserveError>
pub fn try_reserve_exact( &mut self, additional: usize, ) -> Result<(), TryReserveError>
See [’Vec::try_reserve_exact`]
Sourcepub fn with_capcity(capacity: usize) -> Self
pub fn with_capcity(capacity: usize) -> Self
See [’Vec::with_capacity`]
Sourcepub fn binary_search(&self, x: &T) -> Result<usize, usize>where
T: Ord,
pub fn binary_search(&self, x: &T) -> Result<usize, usize>where
T: Ord,
See [[_]::binary_search]
Sourcepub fn binary_search_by<F: FnMut(&T) -> Ordering>(
&self,
f: F,
) -> Result<usize, usize>
pub fn binary_search_by<F: FnMut(&T) -> Ordering>( &self, f: F, ) -> Result<usize, usize>
See [[_]::binary_search]
Sourcepub fn binary_search_by_key<B: Ord, F: FnMut(&T) -> B>(
&self,
b: &B,
f: F,
) -> Result<usize, usize>
pub fn binary_search_by_key<B: Ord, F: FnMut(&T) -> B>( &self, b: &B, f: F, ) -> Result<usize, usize>
See [[_]::binary_search_by_key]
Sourcepub fn fill(&mut self, t: T)where
T: Clone,
pub fn fill(&mut self, t: T)where
T: Clone,
See [[_]::fill]
Note: This replaces items, rather than changing their value, so components which were linked to the list before will not (necessarily) update.
Sourcepub fn fill_with<F: FnMut() -> T>(&mut self, f: F)
pub fn fill_with<F: FnMut() -> T>(&mut self, f: F)
See [[_]::fill_with]
Note: This replaces items, rather than changing their value, so components which were linked to the list before will not (necessarily) update.
Sourcepub unsafe fn get_unchecked(&self, index: usize) -> ListEntry<T>
pub unsafe fn get_unchecked(&self, index: usize) -> ListEntry<T>
See [[_]::get_unchecked]
§Safety
- The index must be in bounds for the slice, otherwise this method is u.b.
Sourcepub fn iter(&self) -> <&Self as IntoIterator>::IntoIter
pub fn iter(&self) -> <&Self as IntoIterator>::IntoIter
See [[_]::iter]
Sourcepub fn partition_point<P: FnMut(&T) -> bool>(&self, pred: P) -> usize
pub fn partition_point<P: FnMut(&T) -> bool>(&self, pred: P) -> usize
See [[_]::partition_point]
Sourcepub fn rotate_left(&mut self, mid: usize)
pub fn rotate_left(&mut self, mid: usize)
See [[_]::rotate_left]
Sourcepub fn rotate_right(&mut self, mid: usize)
pub fn rotate_right(&mut self, mid: usize)
See [[_]::rotate_right]
Sourcepub fn sort_by_cached_key<U: Ord, F: FnMut(&T) -> U>(&mut self, f: F)
pub fn sort_by_cached_key<U: Ord, F: FnMut(&T) -> U>(&mut self, f: F)
See [[_]::sort_by]
Sourcepub fn sort_by_key<U: Ord, F: FnMut(&T) -> U>(&mut self, f: F)
pub fn sort_by_key<U: Ord, F: FnMut(&T) -> U>(&mut self, f: F)
See [[_]::sort_by]
Sourcepub fn sort_unstable(&mut self)where
T: Ord,
pub fn sort_unstable(&mut self)where
T: Ord,
See [[_]::sort]
Sourcepub fn sort_unstable_by_key<U: Ord, F: FnMut(&T) -> U>(&mut self, f: F)
pub fn sort_unstable_by_key<U: Ord, F: FnMut(&T) -> U>(&mut self, f: F)
See [[_]::sort_by]
Sourcepub fn starts_with(&self, needle: &[T]) -> boolwhere
T: PartialEq,
pub fn starts_with(&self, needle: &[T]) -> boolwhere
T: PartialEq,
See [[_]::starts_with]
Trait Implementations§
Source§impl<'a, T: 'a + Clone> Extend<&'a T> for List<T>
impl<'a, T: 'a + Clone> Extend<&'a T> for List<T>
Source§fn extend<I: IntoIterator<Item = &'a T>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = &'a T>>(&mut self, iter: I)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§impl<T> Extend<T> for List<T>
impl<T> Extend<T> for List<T>
Source§fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)