NegIdxVec

Struct NegIdxVec 

Source
pub struct NegIdxVec<T> {
    pub data: Vec<T>,
    /* private fields */
}
Expand description

A vector that can be indexed with a negative index, like with Python.

use libdiffsitter::neg_idx_vec::NegIdxVec;
let v = NegIdxVec::from(vec![1, 2, 3]);
let last_negative = v[-1];
let last = v[(v.len() - 1).try_into().unwrap()];

A negative index corresponds to an offset from the end of the vector.

Fields§

§data: Vec<T>

The underlying vector for the negative index vector

Implementations§

Source§

impl<T> NegIdxVec<T>

Source

pub fn new<F>(len: usize, f: F) -> Self
where F: FnMut() -> T,

Create a negative index vector with a given size.

This will create an internal vector and all offsets will be pegged relative to the size of this vector.

use libdiffsitter::neg_idx_vec::NegIdxVec;
let v: NegIdxVec<usize> = NegIdxVec::new(1, Default::default);
Source

pub fn reserve(&mut self, additional: usize)

Reserve capacity for a number of additional elements.

Source

pub fn reserve_exact(&mut self, additional: usize)

Reserve space for exactly additional elements.

This will not over-allocate.

Source

pub fn capacity(&self) -> usize

Return the total number of elements the vector can hold without requiring another allocation.

Source

pub fn len(&self) -> usize

Get the length of the vector

Source

pub fn is_empty(&self) -> bool

Returns whether the vector is empty.

Trait Implementations§

Source§

impl<T: Clone> Clone for NegIdxVec<T>

Source§

fn clone(&self) -> NegIdxVec<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> Debug for NegIdxVec<T>

Source§

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

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

impl<T> Default for NegIdxVec<T>

Source§

fn default() -> Self

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

impl<T: Clone> From<&[T]> for NegIdxVec<T>

Source§

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

Converts to this type from the input type.
Source§

impl<T> From<Vec<T>> for NegIdxVec<T>

Source§

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

Converts to this type from the input type.
Source§

impl<T> FromIterator<T> for NegIdxVec<T>

Source§

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

Creates a value from an iterator. Read more
Source§

impl<T> Index<i32> for NegIdxVec<T>

Source§

type Output = T

The returned type after indexing.
Source§

fn index(&self, idx: i32) -> &<Self as Index<i32>>::Output

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

impl<T> IndexMut<i32> for NegIdxVec<T>

Source§

fn index_mut(&mut self, idx: i32) -> &mut <Self as Index<i32>>::Output

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

impl<T> IntoIterator for NegIdxVec<T>

Source§

type Item = T

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<<NegIdxVec<T> as IntoIterator>::Item>

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> PartialEq for NegIdxVec<T>

Source§

fn eq(&self, other: &NegIdxVec<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<T: Eq> Eq for NegIdxVec<T>

Source§

impl<T> StructuralPartialEq for NegIdxVec<T>

Auto Trait Implementations§

§

impl<T> Freeze for NegIdxVec<T>

§

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

§

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

§

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

§

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

§

impl<T> UnwindSafe for NegIdxVec<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<I> IntoStreamingIterator for I
where I: IntoIterator,

Source§

fn into_streaming_iter(self) -> Convert<Self::IntoIter>

Source§

fn into_streaming_iter_ref<'a, T>(self) -> ConvertRef<'a, Self::IntoIter, T>
where Self: IntoIterator<Item = &'a T>, T: ?Sized,

Turns an IntoIterator of references into a StreamingIterator. Read more
Source§

fn into_streaming_iter_mut<'a, T>(self) -> ConvertMut<'a, Self::IntoIter, T>
where Self: IntoIterator<Item = &'a mut T>, T: ?Sized,

Turns an IntoIterator of mutable references into a StreamingIteratorMut. 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.