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,
impl<V, S> SetValueList<V, S>where
S: BuildHasher + Default,
Sourcepub fn new(dummy: V) -> Self
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>
impl<V, S> SetValueList<V, S>
Sourcepub fn push_back(&mut self, value: V) -> bool
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"));Sourcepub fn push_front(&mut self, value: V) -> bool
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>>§
Sourcepub fn len(&self) -> usize
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);Sourcepub fn is_empty(&self) -> bool
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());Sourcepub fn front(&self) -> Option<&V>
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"));Sourcepub fn front_mut(&mut self) -> Option<&mut V>
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"));Sourcepub fn back(&self) -> Option<&V>
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"));Sourcepub fn back_mut(&mut self) -> Option<&mut V>
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"));Sourcepub fn values(&self) -> Values<'_, V, S> ⓘ
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".
}Sourcepub fn values_mut(&mut self) -> ValuesMut<'_, V, S> ⓘ
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*".
}Sourcepub fn values_from(&self, cur: ListPos) -> Values<'_, V, S> ⓘ
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".
}Sourcepub fn values_mut_from(&mut self, cur: ListPos) -> ValuesMut<'_, V, S> ⓘ
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*".
}Sourcepub fn iter_next(&self, cur: ListPos) -> Option<(ListPos, &V)>
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");Sourcepub fn iter_next_mut(&mut self, cur: ListPos) -> Option<(ListPos, &mut V)>
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");Sourcepub fn first_position(&self) -> ListPos
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");Sourcepub fn contains_key<Q>(&self, key: &Q) -> bool
pub fn contains_key<Q>(&self, key: &Q) -> bool
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'));Sourcepub fn get_position<Q>(&self, key: &Q) -> Option<ListPos>
pub fn get_position<Q>(&self, key: &Q) -> Option<ListPos>
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();Sourcepub fn get<Q>(&self, key: &Q) -> Option<&V>
pub fn get<Q>(&self, key: &Q) -> Option<&V>
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"));Sourcepub fn get_mut<Q>(&mut self, key: &Q) -> Option<&mut V>
pub fn get_mut<Q>(&mut self, key: &Q) -> Option<&mut V>
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"));Sourcepub fn push_back(&mut self, key: K, value: V) -> bool
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"));Sourcepub fn push_front(&mut self, key: K, value: V) -> bool
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"));Sourcepub fn insert<Q>(&mut self, key: K, value: V, after: &Q) -> bool
pub fn insert<Q>(&mut self, key: K, value: V, after: &Q) -> bool
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');Sourcepub fn remove<Q>(&mut self, key: &Q) -> Option<V>
pub fn remove<Q>(&mut self, key: &Q) -> Option<V>
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"));Sourcepub fn remove_entry<Q>(&mut self, key: &Q) -> Option<(K, V)>
pub fn remove_entry<Q>(&mut self, key: &Q) -> Option<(K, V)>
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")));Sourcepub fn values_as_vec(&self) -> Vec<V>
pub fn values_as_vec(&self) -> Vec<V>
Creates Vec from this list.
Trait Implementations§
Source§impl<V, S> Clone for SetValueList<V, S>
impl<V, S> Clone for SetValueList<V, S>
Source§impl<V, S> Default for SetValueList<V, S>
impl<V, S> Default for SetValueList<V, S>
Source§impl<V, S> Deref for SetValueList<V, S>
impl<V, S> Deref for SetValueList<V, S>
Source§impl<V, S> DerefMut for SetValueList<V, S>
impl<V, S> DerefMut for SetValueList<V, S>
Source§impl<V, S> Display for SetValueList<V, S>where
V: Display,
S: BuildHasher,
impl<V, S> Display for SetValueList<V, S>where
V: Display,
S: BuildHasher,
Source§impl<V, S> From<&[V]> for SetValueList<V, S>
impl<V, S> From<&[V]> for SetValueList<V, S>
Source§impl<V, S> From<SetValueList<V, S>> for Vec<V>where
S: BuildHasher,
impl<V, S> From<SetValueList<V, S>> for Vec<V>where
S: BuildHasher,
Source§fn from(value: SetValueList<V, S>) -> Self
fn from(value: SetValueList<V, S>) -> Self
Source§impl<V, S> IntoIterator for SetValueList<V, S>where
S: BuildHasher,
impl<V, S> IntoIterator for SetValueList<V, S>where
S: BuildHasher,
impl<V, S> Resource for SetValueList<V, S>
Auto Trait Implementations§
impl<V, S> Freeze for SetValueList<V, S>where
S: Freeze,
impl<V, S> RefUnwindSafe for SetValueList<V, S>where
S: RefUnwindSafe,
V: RefUnwindSafe,
impl<V, S> Send for SetValueList<V, S>
impl<V, S> Sync for SetValueList<V, S>
impl<V, S> Unpin for SetValueList<V, S>
impl<V, S> UnwindSafe for SetValueList<V, S>where
V: UnwindSafe,
S: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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