Struct SetValueList

Source
pub struct SetValueList<V, S>(/* private fields */);
Expand description

A list containing unique values.

This list is based on SetList. See documentation of it for more information.

Implementations§

Source§

impl<V, S> SetValueList<V, S>
where S: BuildHasher + Default,

Source

pub fn new(dummy: V) -> Self

Creates a new empty list.

SetValueList requires dummy head node for now, so you can put in any values.

§Examples
use my_ecs::ds::SetValueList;
use std::hash::RandomState;

let list = SetValueList::<&'static str, RandomState>::new("");
Source§

impl<V, S> SetValueList<V, S>
where V: Hash + Eq + Clone, S: BuildHasher,

Source

pub fn push_back(&mut self, value: V) -> bool

Appends the given value to the end of the list.

However, if the list already contains the value, nothing takes place and returns false.

§Examples
use my_ecs::ds::SetValueList;
use std::hash::RandomState;

let mut list = SetValueList::<_, RandomState>::default();
list.push_back("alpha");
assert!(!list.push_back("alpha"));
Source

pub fn push_front(&mut self, value: V) -> bool

Appends the given value to the beginning of the list.

However, if the list already contains the value, nothing takes place and returns false.

§Examples
use my_ecs::ds::SetValueList;
use std::hash::RandomState;

let mut list = SetValueList::<_, RandomState>::default();
list.push_front("alpha");
assert!(!list.push_front("alpha"));

Methods from Deref<Target = SetList<V, V, S>>§

Source

pub fn len(&self) -> usize

Returns number of items.

§Examples
use my_ecs::ds::SetList;
use std::hash::RandomState;

let mut list = SetList::<_, _, RandomState>::default();
list.push_back('a', "alpha");
assert_eq!(list.len(), 1);
Source

pub fn is_empty(&self) -> bool

Returns true if the list is empty.

§Examples
use my_ecs::ds::SetList;
use std::hash::RandomState;

let mut list = SetList::<char, &'static str, RandomState>::default();
assert!(list.is_empty());
Source

pub fn front(&self) -> Option<&V>

Returns a shared reference to the front item.

§Examples
use my_ecs::ds::SetList;
use std::hash::RandomState;

let mut list = SetList::<_, _, RandomState>::default();
list.push_back('a', "alpha");
list.push_back('b', "beta");
assert_eq!(list.front(), Some(&"alpha"));
Source

pub fn front_mut(&mut self) -> Option<&mut V>

Returns a mutable reference to the front item.

§Examples
use my_ecs::ds::SetList;
use std::hash::RandomState;

let mut list = SetList::<_, _, RandomState>::default();
list.push_back('a', "alpha");
list.push_back('b', "beta");
assert_eq!(list.front_mut(), Some(&mut "alpha"));
Source

pub fn back(&self) -> Option<&V>

Returns a shared reference to the last item.

§Examples
use my_ecs::ds::SetList;
use std::hash::RandomState;

let mut list = SetList::<_, _, RandomState>::default();
list.push_back('a', "alpha");
list.push_back('b', "beta");
assert_eq!(list.back(), Some(&"beta"));
Source

pub fn back_mut(&mut self) -> Option<&mut V>

Returns a mutable reference to the last item.

§Examples
use my_ecs::ds::SetList;
use std::hash::RandomState;

let mut list = SetList::<_, _, RandomState>::default();
list.push_back('a', "alpha");
list.push_back('b', "beta");
assert_eq!(list.back_mut(), Some(&mut "beta"));
Source

pub fn values(&self) -> Values<'_, V, S>

Returns an iterator visiting all values in order.

§Examples
use my_ecs::ds::SetList;
use std::hash::RandomState;

let mut list = SetList::<_, _, RandomState>::default();
list.push_back('a', "alpha");
list.push_back('b', "beta");

for v in list.values() {
    println!("{v}"); // Prints out "alpha" and "beta".
}
Source

pub fn values_mut(&mut self) -> ValuesMut<'_, V, S>

Returns a mutable iterator visiting all values in order.

§Examples
use my_ecs::ds::SetList;
use std::hash::RandomState;

let mut list = SetList::<_, _, RandomState>::default();
list.push_back('a', "alpha".to_owned());
list.push_back('b', "beta".to_owned());

for v in list.values_mut() {
    v.push('*');
    println!("{v}"); // Prints out "alpha*" and "beta*".
}
Source

pub fn values_from(&self, cur: ListPos) -> Values<'_, V, S>

Returns an iterator visiting values from the given position.

§Panics

Panics if the position is not valid one for the list.

§Examples
use my_ecs::ds::SetList;
use std::hash::RandomState;

let mut list = SetList::<_, _, RandomState>::default();
list.push_back('a', "alpha");
list.push_back('b', "beta");
list.push_back('g', "gamma");

let pos = list.get_position(&'b').unwrap();
for v in list.values_from(pos) {
    println!("{v}"); // Prints out "beta" and "gamma".
}
Source

pub fn values_mut_from(&mut self, cur: ListPos) -> ValuesMut<'_, V, S>

Returns a mutable iterator visiting values from the given position.

§Panics

Panics if the position is not valid one for the list.

§Examples
use my_ecs::ds::SetList;
use std::hash::RandomState;

let mut list = SetList::<_, _, RandomState>::default();
list.push_back('a', "alpha".to_owned());
list.push_back('b', "beta".to_owned());
list.push_back('g', "gamma".to_owned());

let pos = list.get_position(&'b').unwrap();
for v in list.values_mut_from(pos) {
    v.push('*');
    println!("{v}"); // Prints out "beta*" and "gamma*".
}
Source

pub fn iter_next(&self, cur: ListPos) -> Option<(ListPos, &V)>

Returns a shared reference to a value at the given position with the next position.

If the given position is not valid one for the list, returns None.

§Examples
use my_ecs::ds::SetList;
use std::hash::RandomState;

let mut list = SetList::<_, _, RandomState>::default();
list.push_back('a', "alpha");
list.push_back('b', "beta");

let pos = list.get_position(&'b').unwrap();
let (_, v) = list.iter_next(pos).unwrap();
assert_eq!(v, &"beta");
Source

pub fn iter_next_mut(&mut self, cur: ListPos) -> Option<(ListPos, &mut V)>

Returns a mutable reference to a value at the given position with the next position.

If the given position is not valid one for the list, returns None.

§Examples
use my_ecs::ds::SetList;
use std::hash::RandomState;

let mut list = SetList::<_, _, RandomState>::default();
list.push_back('a', "alpha");
list.push_back('b', "beta");

let pos = list.get_position(&'b').unwrap();
let (_, v) = list.iter_next_mut(pos).unwrap();
assert_eq!(v, &mut "beta");
Source

pub fn first_position(&self) -> ListPos

Returns the first position of the list.

§Examples
use my_ecs::ds::SetList;
use std::hash::RandomState;

let mut list = SetList::<_, _, RandomState>::default();
list.push_back('a', "alpha");
list.push_back('b', "beta");

let pos = list.first_position();
let (_, v) = list.iter_next(pos).unwrap();
assert_eq!(v, &"alpha");
Source

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

Returns true if the vector contains the given key.

§Examples
use my_ecs::ds::SetList;
use std::hash::RandomState;

let mut list = SetList::<_, _, RandomState>::default();
list.push_back('a', "alpha");
assert!(list.contains_key(&'a'));
Source

pub fn get_position<Q>(&self, key: &Q) -> Option<ListPos>
where K: Borrow<Q>, Q: Hash + Eq + ?Sized,

Retrieves a position of a value corresponding to the given key.

§Examples
use my_ecs::ds::SetList;
use std::hash::RandomState;

let mut list = SetList::<_, _, RandomState>::default();
list.push_back('a', "alpha");
let pos = list.get_position(&'a').unwrap();
Source

pub fn get<Q>(&self, key: &Q) -> Option<&V>
where K: Borrow<Q>, Q: Hash + Eq + ?Sized,

Retrieves a shared reference to a value corresponding to the given key.

§Examples
use my_ecs::ds::SetList;
use std::hash::RandomState;

let mut list = SetList::<_, _, RandomState>::default();
list.push_back('a', "alpha");
assert_eq!(list.get(&'a'), Some(&"alpha"));
Source

pub fn get_mut<Q>(&mut self, key: &Q) -> Option<&mut V>
where K: Borrow<Q>, Q: Hash + Eq + ?Sized,

Retrieves a mutable reference to a value corresponding to the given key.

§Examples
use my_ecs::ds::SetList;
use std::hash::RandomState;

let mut list = SetList::<_, _, RandomState>::default();
list.push_back('a', "alpha");
assert_eq!(list.get_mut(&'a'), Some(&mut "alpha"));
Source

pub fn push_back(&mut self, key: K, value: V) -> bool

Appends the given key-value pair to the end of the list.

However, if the list already contains the key, nothing takes place and returns false.

§Examples
use my_ecs::ds::SetList;
use std::hash::RandomState;

let mut list = SetList::<_, _, RandomState>::default();
list.push_back('a', "alpha");
assert!(!list.push_back('a', "beta"));
assert_eq!(list.back(), Some(&"alpha"));
Source

pub fn push_front(&mut self, key: K, value: V) -> bool

Inserts the given key-value pair to the beginning of the list.

However, if the list already contains the key, nothing takes place and returns false.

§Examples
use my_ecs::ds::SetList;
use std::hash::RandomState;

let mut list = SetList::<_, _, RandomState>::default();
list.push_front('a', "alpha");
assert!(!list.push_front('a', "beta"));
assert_eq!(list.front(), Some(&"alpha"));
Source

pub fn insert<Q>(&mut self, key: K, value: V, after: &Q) -> bool
where K: Borrow<Q>, Q: Hash + Eq + ?Sized,

Inserts the given key-value pair after a node corresponding to after.

However, if the list already contains the key or doesn’t contain after, nothing takes place and returns false.

§Examples
use my_ecs::ds::SetList;
use std::hash::RandomState;

let mut list = SetList::<_, _, RandomState>::default();
list.push_back('a', "alpha");
list.push_back('g', "gamma");
list.insert('b', "beta", &'a');
Source

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

Removes an item corresponding to the given key.

§Examples
use my_ecs::ds::SetList;
use std::hash::RandomState;

let mut list = SetList::<_, _, RandomState>::default();
list.push_back('a', "alpha");
assert_eq!(list.remove(&'a'), Some("alpha"));
Source

pub fn remove_entry<Q>(&mut self, key: &Q) -> Option<(K, V)>
where K: Borrow<Q>, Q: Hash + Eq + ?Sized,

Removes an item corresponding to the given key then resturns key-value pair.

§Examples
use my_ecs::ds::SetList;
use std::hash::RandomState;

let mut list = SetList::<_, _, RandomState>::default();
list.push_back('a', "alpha");
assert_eq!(list.remove_entry(&'a'), Some(('a', "alpha")));
Source

pub fn values_as_vec(&self) -> Vec<V>

Creates Vec from this list.

Trait Implementations§

Source§

impl<V, S> Clone for SetValueList<V, S>
where V: Clone, S: Clone,

Source§

fn clone(&self) -> Self

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<V: Debug, S: Debug> Debug for SetValueList<V, S>

Source§

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

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

impl<V, S> Default for SetValueList<V, S>
where V: Default, S: BuildHasher + Default,

Source§

fn default() -> Self

Creates a new empty list.

§Examples
use my_ecs::ds::SetValueList;
use std::hash::RandomState;

let list = SetValueList::<&'static str, RandomState>::default();
Source§

impl<V, S> Deref for SetValueList<V, S>

Source§

type Target = SetList<V, V, S>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<V, S> DerefMut for SetValueList<V, S>

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl<V, S> Display for SetValueList<V, S>
where V: Display, S: BuildHasher,

Source§

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

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

impl<V, S> From<&[V]> for SetValueList<V, S>
where V: Hash + Eq + Clone + Default, S: BuildHasher + Default,

Source§

fn from(value: &[V]) -> Self

Converts to this type from the input type.
Source§

impl<V, S> From<SetValueList<V, S>> for Vec<V>
where S: BuildHasher,

Source§

fn from(value: SetValueList<V, S>) -> Self

Converts to this type from the input type.
Source§

impl<V, S> IntoIterator for SetValueList<V, S>
where S: BuildHasher,

Source§

type Item = V

The type of the elements being iterated over.
Source§

type IntoIter = IntoValues<V, S>

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<V, S> Resource for SetValueList<V, S>
where V: Send + 'static, S: Send + 'static,

Auto Trait Implementations§

§

impl<V, S> Freeze for SetValueList<V, S>
where S: Freeze,

§

impl<V, S> RefUnwindSafe for SetValueList<V, S>

§

impl<V, S> Send for SetValueList<V, S>
where S: Send, V: Send,

§

impl<V, S> Sync for SetValueList<V, S>
where S: Sync, V: Sync,

§

impl<V, S> Unpin for SetValueList<V, S>
where S: Unpin, V: Unpin,

§

impl<V, S> UnwindSafe for SetValueList<V, S>
where V: UnwindSafe, S: 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> 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> 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<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> 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> 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, 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.