List

Struct List 

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

Source

pub fn append(&mut self, o: &mut Self)

Source

pub fn capacity(&self) -> usize

Source

pub fn clear(&mut self)

Source

pub fn dedup(&mut self)
where T: PartialEq,

Source

pub fn dedup_by<F: FnMut(&T, &T) -> bool>(&mut self, f: F)

Source

pub fn dedup_by_key<K: PartialEq, F: FnMut(&T) -> K>(&mut self, f: F)

Source

pub fn drain<R: RangeBounds<usize>>(&mut self, range: R) -> Drain<'_, T>
where T: 'static,

Source

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

Source

pub fn is_empty(&self) -> bool

Source

pub fn len(&self) -> usize

Source

pub fn new() -> Self

Source

pub fn pop(&mut self) -> Option<Shared<T, W>>

Source

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

Source

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

Source

pub fn reserve(&mut self, additional: usize)

Source

pub fn reserve_exact(&mut self, additional: usize)

Source

pub fn resize(&mut self, new_len: usize, t: T)
where T: Clone,

Source

pub fn resize_with<F: FnMut() -> T>(&mut self, new_len: usize, f: F)

Source

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

Source

pub fn retain_mut<F: FnMut(&mut ListEntry<T>) -> bool>(&mut self, f: F)
where T: 'static,

Source

pub fn shrink_to(&mut self, min_capacity: usize)

Source

pub fn shrink_to_fit(&mut self)

Source

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,

Source

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

Source

pub fn swap_remove(&mut self, index: usize) -> Shared<T, W>

Source

pub fn truncate(&mut self, len: usize)

See [’Vec::truncate`]

Source

pub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError>

See [’Vec::try_reserve`]

Source

pub fn try_reserve_exact( &mut self, additional: usize, ) -> Result<(), TryReserveError>

See [’Vec::try_reserve_exact`]

Source

pub fn with_capcity(capacity: usize) -> Self

See [’Vec::with_capacity`]

See [[_]::binary_search]

Source

pub fn binary_search_by<F: FnMut(&T) -> Ordering>( &self, f: F, ) -> Result<usize, usize>

See [[_]::binary_search]

Source

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]

Source

pub fn contains(&self, x: &T) -> bool
where T: PartialEq,

See [[_]::contains]

Source

pub fn ends_with(&self, needle: &[T]) -> bool
where T: PartialEq,

See [[_]::ends_with]

Source

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.

Source

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.

Source

pub fn first(&self) -> Option<ListEntry<T>>

See [[_]::first]

Source

pub fn get(&self, index: usize) -> Option<ListEntry<T>>

See [[_]::get]

Source

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

pub fn iter(&self) -> <&Self as IntoIterator>::IntoIter

See [[_]::iter]

Source

pub fn last(&self) -> Option<ListEntry<T>>

See [[_]::last]

Source

pub fn partition_point<P: FnMut(&T) -> bool>(&self, pred: P) -> usize

See [[_]::partition_point]

Source

pub fn reverse(&mut self)

See [[_]::reverse]

Source

pub fn rotate_left(&mut self, mid: usize)

See [[_]::rotate_left]

Source

pub fn rotate_right(&mut self, mid: usize)

See [[_]::rotate_right]

Source

pub fn sort(&mut self)
where T: Ord,

See [[_]::sort]

Source

pub fn sort_by<F: FnMut(&T, &T) -> Ordering>(&mut self, f: F)

See [[_]::sort_by]

Source

pub fn sort_by_cached_key<U: Ord, F: FnMut(&T) -> U>(&mut self, f: F)

See [[_]::sort_by]

Source

pub fn sort_by_key<U: Ord, F: FnMut(&T) -> U>(&mut self, f: F)

See [[_]::sort_by]

Source

pub fn sort_unstable(&mut self)
where T: Ord,

See [[_]::sort]

Source

pub fn sort_unstable_by<F: FnMut(&T, &T) -> Ordering>(&mut self, f: F)

See [[_]::sort_by]

Source

pub fn sort_unstable_by_key<U: Ord, F: FnMut(&T) -> U>(&mut self, f: F)

See [[_]::sort_by]

Source

pub fn starts_with(&self, needle: &[T]) -> bool
where T: PartialEq,

See [[_]::starts_with]

Source

pub fn swap(&mut self, a: usize, b: usize)

See [[_]::swap]

Trait Implementations§

Source§

impl<T> Default for List<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'a, T: 'a + Clone> Extend<&'a T> for List<T>

Source§

fn extend<I: IntoIterator<Item = &'a T>>(&mut self, iter: I)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<T> Extend<T> for List<T>

Source§

fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<T> FromIterator<T> for List<T>

Source§

fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl<'a, T> IntoIterator for &'a List<T>

Source§

type Item = ListEntry<T>

The type of the elements being iterated over.
Source§

type IntoIter = Cloned<Iter<'a, ListEntry<T>>>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl<T> Freeze for List<T>

§

impl<T> !RefUnwindSafe for List<T>

§

impl<T> Send for List<T>
where T: Send + Sync,

§

impl<T> Sync for List<T>
where T: Send + Sync,

§

impl<T> Unpin for List<T>

§

impl<T> !UnwindSafe for List<T>

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

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, 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.