Skip to main content

ItemList

Struct ItemList 

Source
pub struct ItemList<T: A2lObjectName> { /* private fields */ }
Expand description

A list of named a2l items

An ItemList is an ordered collection of items, which additionally allows for fast access to items by their name.

Implementations§

Source§

impl<T: A2lObjectName> ItemList<T>

Source

pub fn new() -> Self

create a new ItemList

Source

pub fn with_capacity(capacity: usize) -> Self

create a new ItemList with a specified initial capacity

Source

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

push an item into the ItemList

Source

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

push an item into the ItemList, replacing any existing item with the same name

Source

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

pop an item from the ItemList

Source

pub fn get(&self, key: &str) -> Option<&T>

get an item by key

Source

pub fn get_mut(&mut self, key: &str) -> Option<&mut T>

get a mutable reference to an item by key

Source

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

get the first item in the ItemList

Source

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

get the last item in the ItemList

Source

pub fn index(&self, key: &str) -> Option<usize>

get the index of an item by key

Source

pub fn contains_key(&self, key: &str) -> bool

Checks if the ItemList contains an item with the given key

Source

pub fn swap_remove(&mut self, key: &str) -> Option<T>

remove an item from the ItemList by key and return it

Source

pub fn swap_remove_idx(&mut self, index: usize) -> Option<T>

remove an item from the ItemList by index and return it

Source

pub fn iter(&self) -> impl Iterator<Item = &T>

Returns an iterator over references to the items in the ItemList

Source

pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut T>

Returns an iterator over mutable references to the items in the ItemList

Source

pub fn keys(&self) -> impl Iterator<Item = &String>

Returns an iterator over the keys in the ItemList

Source

pub fn len(&self) -> usize

Returns the number of items in the ItemList

Source

pub fn is_empty(&self) -> bool

Checks if the ItemList is empty

Source

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

extend the ItemList from an iterator

Source

pub fn clear(&mut self)

remove all items from the ItemList

Source

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

trucate the ItemList to a specified length

Source

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

Selectively remove or retain items from the ItemList based on a predicate function

Source

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

Source§

impl<T: A2lObjectName + A2lObjectNameSetter> ItemList<T>

Source

pub fn rename_item(&mut self, item_idx: usize, new_name: &str)

Set the name of an item in the ItemList

Trait Implementations§

Source§

impl<T: Clone + A2lObjectName> Clone for ItemList<T>

Source§

fn clone(&self) -> ItemList<T>

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: Debug + A2lObjectName> Debug for ItemList<T>

Source§

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

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

impl<T> Default for ItemList<T>
where T: A2lObjectName,

Source§

fn default() -> Self

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

impl<T> FromIterator<T> for ItemList<T>
where T: A2lObjectName,

Source§

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

Creates a value from an iterator. Read more
Source§

impl<T: A2lObjectName> Index<&str> for ItemList<T>

Source§

type Output = T

The returned type after indexing.
Source§

fn index(&self, key: &str) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<T: A2lObjectName> Index<usize> for ItemList<T>

Source§

type Output = T

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<T: A2lObjectName> IndexMut<usize> for ItemList<T>

Source§

fn index_mut(&mut self, index: usize) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<'a, T> IntoIterator for &'a ItemList<T>
where T: A2lObjectName,

Source§

type Item = &'a T

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, 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
Source§

impl<'a, T> IntoIterator for &'a mut ItemList<T>
where T: A2lObjectName,

Source§

type Item = &'a mut T

The type of the elements being iterated over.
Source§

type IntoIter = IterMut<'a, 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
Source§

impl<T> IntoIterator for ItemList<T>
where T: A2lObjectName,

Source§

type Item = T

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<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
Source§

impl<T> PartialEq for ItemList<T>

Source§

fn eq(&self, other: &Self) -> 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.

Auto Trait Implementations§

§

impl<T> Freeze for ItemList<T>

§

impl<T> RefUnwindSafe for ItemList<T>
where T: RefUnwindSafe,

§

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

§

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

§

impl<T> Unpin for ItemList<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for ItemList<T>

§

impl<T> UnwindSafe for ItemList<T>
where T: UnwindSafe,

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