charon_lib::ids::vector

Struct Vector

source
pub struct Vector<I, T>
where I: Idx,
{ vector: IndexVec<I, Option<T>>, real_len: usize, }
Expand description

Indexed vector. To prevent accidental id reuse, the vector supports reserving a slot to be filled later.

Fields§

§vector: IndexVec<I, Option<T>>§real_len: usize

The number of non-None elements.

Implementations§

source§

impl<I, T> Vector<I, T>
where I: Idx,

source

pub fn new() -> Self

source

pub fn get(&self, i: I) -> Option<&T>

source

pub fn get_mut(&mut self, i: I) -> Option<&mut T>

source

pub fn is_empty(&self) -> bool

source

pub fn len(&self) -> usize

source

pub fn next_id(&self) -> I

Gets the value of the next available id. Avoid if possible; use reserve_slot instead.

source

pub fn reserve_slot(&mut self) -> I

Reserve a spot in the vector.

source

pub fn set_slot(&mut self, id: I, x: T)

Fill the reserved slot.

source

pub fn remove(&mut self, id: I) -> Option<T>

Remove the value from this slot.

source

pub fn push(&mut self, x: T) -> I

source

pub fn push_with(&mut self, f: impl FnOnce(I) -> T) -> I

source

pub fn map<U>(self, f: impl FnMut(T) -> U) -> Vector<I, U>

Map each entry to a new one, keeping the same ids.

source

pub fn map_ref<'a, U>(&'a self, f: impl FnMut(&'a T) -> U) -> Vector<I, U>

Map each entry to a new one, keeping the same ids.

source

pub fn map_ref_mut<'a, U>( &'a mut self, f: impl FnMut(&'a mut T) -> U, ) -> Vector<I, U>

Map each entry to a new one, keeping the same ids.

source

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

Iter over the nonempty slots.

source

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

source

pub fn iter_indexed(&self) -> impl Iterator<Item = (I, &T)>

source

pub fn into_iter_indexed(self) -> impl Iterator<Item = (I, T)>

source

pub fn iter_indexed_values(&self) -> impl Iterator<Item = (I, &T)>

source

pub fn into_iter_indexed_values(self) -> impl Iterator<Item = (I, T)>

source

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

Iterate over all slots, even empty ones.

source

pub fn iter_indexed_all_slots(&self) -> impl Iterator<Item = (I, &Option<T>)>

source

pub fn iter_indices(&self) -> impl Iterator<Item = I> + '_

source

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

Like Vec::split_off.

Trait Implementations§

source§

impl<I, T: Clone> Clone for Vector<I, T>
where I: Idx + Clone,

source§

fn clone(&self) -> Vector<I, T>

Returns a copy 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<I, T: Debug> Debug for Vector<I, T>
where I: Idx + Debug,

source§

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

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

impl<I: Idx, T> Default for Vector<I, T>

source§

fn default() -> Self

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

impl<'de, I: Idx, T: Deserialize<'de>> Deserialize<'de> for Vector<I, T>

source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<I: Idx, T: Drive> Drive for Vector<I, T>

source§

fn drive<V: Visitor>(&self, visitor: &mut V)

source§

impl<I: Idx, T: DriveMut> DriveMut for Vector<I, T>

source§

fn drive_mut<V: VisitorMut>(&mut self, visitor: &mut V)

source§

impl<'a> Formatter<&Vector<BlockId, BlockData>> for FmtCtx<'a>

source§

impl<I, T> From<Vec<T>> for Vector<I, T>
where I: Idx,

source§

fn from(v: Vec<T>) -> Self

Converts to this type from the input type.
source§

impl<I, T> FromIterator<T> for Vector<I, T>
where I: Idx,

source§

fn from_iter<It: IntoIterator<Item = T>>(iter: It) -> Vector<I, T>

Creates a value from an iterator. Read more
source§

impl<I, T: Hash> Hash for Vector<I, T>
where I: Idx + Hash,

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<I, R, T> Index<R> for Vector<I, T>
where I: Idx, R: IdxSliceIndex<I, Option<T>, Output = Option<T>>,

source§

type Output = T

The returned type after indexing.
source§

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

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

impl<I, R, T> IndexMut<R> for Vector<I, T>
where I: Idx, R: IdxSliceIndex<I, Option<T>, Output = Option<T>>,

source§

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

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

impl<'a, I, T> IntoIterator for &'a Vector<I, T>
where I: Idx,

source§

type Item = &'a T

The type of the elements being iterated over.
source§

type IntoIter = impl Iterator<Item = &'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, I, T> IntoIterator for &'a mut Vector<I, T>
where I: Idx,

source§

type Item = &'a mut T

The type of the elements being iterated over.
source§

type IntoIter = impl Iterator<Item = &'a mut 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<I, T> IntoIterator for Vector<I, T>
where I: Idx,

source§

type Item = T

The type of the elements being iterated over.
source§

type IntoIter = impl Iterator<Item = 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<I, T: Ord> Ord for Vector<I, T>
where I: Idx + Ord,

source§

fn cmp(&self, other: &Vector<I, T>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
source§

impl<I, T: PartialEq> PartialEq for Vector<I, T>
where I: Idx + PartialEq,

source§

fn eq(&self, other: &Vector<I, T>) -> 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.
source§

impl<I, T: PartialOrd> PartialOrd for Vector<I, T>
where I: Idx + PartialOrd,

source§

fn partial_cmp(&self, other: &Vector<I, T>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<I: Idx, T: Serialize> Serialize for Vector<I, T>

source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl<I, T: Eq> Eq for Vector<I, T>
where I: Idx + Eq,

source§

impl<I, T> StructuralPartialEq for Vector<I, T>
where I: Idx,

Auto Trait Implementations§

§

impl<I, T> Freeze for Vector<I, T>

§

impl<I, T> RefUnwindSafe for Vector<I, T>
where T: RefUnwindSafe,

§

impl<I, T> Send for Vector<I, T>
where T: Send,

§

impl<I, T> Sync for Vector<I, T>
where T: Sync,

§

impl<I, T> Unpin for Vector<I, T>
where T: Unpin,

§

impl<I, T> UnwindSafe for Vector<I, 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, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
§

impl<I, T> ExtractContext<I, ()> for T

§

fn extract_context(self, _original_input: I)

Given the context attached to a nom error, and given the original input to the nom parser, extract more the useful context information. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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
§

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

§

type Collection = T

§

fn join_with<S>(self, sep: S) -> Join<T, S>

Combine this object with a separator to create a new [Join] instance. Note that the separator does not have to share the same type as the iterator’s values. Read more
§

fn join_concat(self) -> Join<Self::Collection, NoSeparator>

Join this object with an empty separator. When rendered with Display, the underlying elements will be directly concatenated. Note that the separator, while empty, is still present, and will show up if you iterate this instance. Read more
§

impl<I> RecreateContext<I> for I

§

fn recreate_context(_original_input: I, tail: I) -> I

Given the original input, as well as the context reported by nom, recreate a context in the original string where the error occurred. Read more
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.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,