[−][src]Struct transit_model_collection::Collection
The Collection
object looks like a Map<Idx<T>, T>
, with opaque
keys. Then, you can easily store indices and don't mess up
between different types of indices.
Methods
impl<T> Collection<T>
[src]
pub fn new(v: Vec<T>) -> Self
[src]
Creates the Collection
from a Vec
.
Examples
use transit_model_collection::Collection; let _: Collection<i32> = Collection::new(vec![1, 1, 2, 3, 5, 8]);
pub fn len(&self) -> usize
[src]
Returns the number of elements in the collection, also referred to as its 'length'.
Examples
use transit_model_collection::Collection; let c: Collection<i32> = Collection::new(vec![1, 1, 2, 3, 5, 8]); assert_eq!(6, c.len());
pub fn iter(&self) -> Iter<T>
[src]
Iterates over the (Idx<T>, &T)
of the Collection
.
Examples
use transit_model_collection::{Collection, Idx}; let c: Collection<i32> = Collection::new(vec![1, 1, 2, 3, 5, 8]); let (k, v): (Idx<i32>, &i32) = c.iter().nth(4).unwrap(); assert_eq!(&5, v); assert_eq!(&5, &c[k]);
pub fn values(&self) -> Iter<T>
[src]
Iterates over the &T
of the Collection
.
Examples
use transit_model_collection::Collection; let c: Collection<i32> = Collection::new(vec![1, 1, 2, 3, 5, 8]); let values: Vec<&i32> = c.values().collect(); assert_eq!(vec![&1, &1, &2, &3, &5, &8], values);
pub fn values_mut(&mut self) -> IterMut<T>
[src]
Iterates over the &mut T
of the Collection
.
Examples
use transit_model_collection::Collection; let mut c: Collection<i32> = Collection::new(vec![1, 1, 2, 3, 5, 8]); for elem in c.values_mut() { *elem *= 2; } assert_eq!(Collection::new(vec![2, 2, 4, 6, 10, 16]), c);
pub fn iter_from<I>(&self, indexes: I) -> impl Iterator<Item = &T> where
I: IntoIterator,
I::Item: Borrow<Idx<T>>,
[src]
I: IntoIterator,
I::Item: Borrow<Idx<T>>,
Iterates on the objects corresponding to the given indices.
Examples
use transit_model_collection::{Collection, Idx}; use std::collections::BTreeSet; let c = Collection::new(vec!["bike", "bus", "walking", "car", "metro", "train"]); let transit_indices: BTreeSet<Idx<&str>> = get_transit_indices(&c); let transit_refs: Vec<&&str> = c.iter_from(&transit_indices).collect(); assert_eq!(vec![&"bus", &"metro", &"train"], transit_refs);
pub fn push(&mut self, item: T) -> Idx<T>
[src]
Push an element in the Collection
without control.
Examples
use transit_model_collection::{Collection, Id}; #[derive(PartialEq, Debug)] struct Obj(&'static str); let mut c = Collection::default(); let foo_idx = c.push(Obj("foo")); let bar_idx = c.push(Obj("bar")); assert_eq!(&Obj("foo"), &c[foo_idx]); assert_ne!(&Obj("bar"), &c[foo_idx]);
pub fn merge(&mut self, other: Self)
[src]
Merge a Collection
parameter into the current one.
Examples
use transit_model_collection::Collection; #[derive(PartialEq, Debug)] struct Obj(&'static str); let mut c1 = Collection::from(Obj("foo")); let c2 = Collection::from(Obj("bar")); c1.merge(c2); assert_eq!(2, c1.len());
pub fn take(&mut self) -> Vec<T>
[src]
Takes the corresponding vector without clones or allocation,
leaving self
empty.
Examples
use transit_model_collection::Collection; #[derive(PartialEq, Debug)] struct Obj(&'static str); let mut c = Collection::new(vec![Obj("foo"), Obj("bar")]); let v = c.take(); assert_eq!(vec![Obj("foo"), Obj("bar")], v); assert_eq!(0, c.len());
pub fn is_empty(&self) -> bool
[src]
Examples
use transit_model_collection::Collection; #[derive(PartialEq, Debug)] struct Obj; let mut c: Collection<Obj> = Collection::default(); assert!(c.is_empty());
pub fn retain<F: FnMut(&T) -> bool>(&mut self, f: F)
[src]
Retains the elements matching predicate parameter from the current CollectionWithId
object
Examples
use transit_model_collection::Collection; use std::collections::HashSet; #[derive(PartialEq, Debug)] struct Obj(&'static str); let mut c = Collection::new(vec![Obj("foo"), Obj("bar"), Obj("qux")]); let mut ids_to_keep: HashSet<String> = HashSet::new(); ids_to_keep.insert("foo".to_string()); ids_to_keep.insert("qux".to_string()); c.retain(|item| ids_to_keep.contains(item.0)); assert_eq!(2, c.len()); assert_eq!(vec!["foo", "qux"], c.values().map(|obj| obj.0).collect::<Vec<&str>>());
Trait Implementations
impl<T: Clone> Clone for Collection<T>
[src]
fn clone(&self) -> Collection<T>
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<T: Debug> Debug for Collection<T>
[src]
impl<T> Default for Collection<T>
[src]
impl<'de, T> Deserialize<'de> for Collection<T> where
T: Deserialize<'de>,
[src]
T: Deserialize<'de>,
fn deserialize<D>(deserializer: D) -> StdResult<Self, D::Error> where
D: Deserializer<'de>,
[src]
D: Deserializer<'de>,
impl<T> From<T> for Collection<T>
[src]
Creates a Collection
from one element.
Examples
use transit_model_collection::Collection; let collection: Collection<i32> = Collection::from(42); assert_eq!(1, collection.len()); let integer = collection.into_iter().next().unwrap(); assert_eq!(42, integer);
impl<T> Index<Idx<T>> for Collection<T>
[src]
type Output = T
The returned type after indexing.
fn index(&self, index: Idx<T>) -> &Self::Output
[src]
impl<'a, T> IntoIterator for &'a Collection<T>
[src]
type Item = (Idx<T>, &'a T)
The type of the elements being iterated over.
type IntoIter = Iter<'a, T>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Iter<'a, T>
[src]
impl<T> IntoIterator for Collection<T>
[src]
type Item = T
The type of the elements being iterated over.
type IntoIter = IntoIter<T>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
impl<T: PartialEq> PartialEq<Collection<T>> for Collection<T>
[src]
fn eq(&self, other: &Collection<T>) -> bool
[src]
#[must_use]fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl<T> Serialize for Collection<T> where
T: Serialize,
[src]
T: Serialize,
Auto Trait Implementations
impl<T> RefUnwindSafe for Collection<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> Send for Collection<T> where
T: Send,
T: Send,
impl<T> Sync for Collection<T> where
T: Sync,
T: Sync,
impl<T> Unpin for Collection<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for Collection<T> where
T: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,
impl<T> From<!> for T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<I> IntoIterator for I where
I: Iterator,
[src]
I: Iterator,
type Item = <I as Iterator>::Item
The type of the elements being iterated over.
type IntoIter = I
Which kind of iterator are we turning this into?
fn into_iter(self) -> I
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,