Struct dioxus_shareables::list::List
source · [−]pub struct List<T>(_);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_without_hook().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
sourceimpl<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<'a, R: RangeBounds<usize>>(
&'a mut self,
range: R
) -> Map<Drain<'a, ListEntry<T>>, fn(_: ListEntry<T>) -> Shared<T, W>>where
T: 'static,
pub fn drain<'a, R: RangeBounds<usize>>(
&'a mut self,
range: R
) -> Map<Drain<'a, ListEntry<T>>, fn(_: ListEntry<T>) -> Shared<T, W>>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]
sourcepub fn iter<'a>(&'a self) -> <&'a Self as IntoIterator>::IntoIter
pub fn iter<'a>(&'a self) -> <&'a 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
sourceimpl<'a, T: 'a + Clone> Extend<&'a T> for List<T>
impl<'a, T: 'a + Clone> Extend<&'a T> for List<T>
sourcefn extend<I: IntoIterator<Item = &'a T>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = &'a T>>(&mut self, iter: I)
Extends a collection with the contents of an iterator. Read more
sourcefn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Extends a collection with exactly one element.
sourcefn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Reserves capacity in a collection for the given number of additional elements. Read more
sourceimpl<T> Extend<T> for List<T>
impl<T> Extend<T> for List<T>
sourcefn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)
Extends a collection with the contents of an iterator. Read more
sourcefn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Extends a collection with exactly one element.
sourcefn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Reserves capacity in a collection for the given number of additional elements. Read more
sourceimpl<T> FromIterator<T> for List<T>
impl<T> FromIterator<T> for List<T>
sourcefn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self
Creates a value from an iterator. Read more
Auto Trait Implementations
impl<T> !RefUnwindSafe for List<T>
impl<T> !Send for List<T>
impl<T> !Sync for List<T>
impl<T> Unpin for List<T>
impl<T> !UnwindSafe for List<T>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more