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>
impl<T> NegIdxVec<T>
Sourcepub fn new<F>(len: usize, f: F) -> Selfwhere
F: FnMut() -> T,
pub fn new<F>(len: usize, f: F) -> Selfwhere
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);Sourcepub fn reserve(&mut self, additional: usize)
pub fn reserve(&mut self, additional: usize)
Reserve capacity for a number of additional elements.
Sourcepub fn reserve_exact(&mut self, additional: usize)
pub fn reserve_exact(&mut self, additional: usize)
Reserve space for exactly additional elements.
This will not over-allocate.
Trait Implementations§
Source§impl<T> FromIterator<T> for NegIdxVec<T>
impl<T> FromIterator<T> for NegIdxVec<T>
Source§fn from_iter<Iter: IntoIterator<Item = T>>(iter: Iter) -> Self
fn from_iter<Iter: IntoIterator<Item = T>>(iter: Iter) -> Self
Creates a value from an iterator. Read more
Source§impl<T> IntoIterator for NegIdxVec<T>
impl<T> IntoIterator for NegIdxVec<T>
impl<T: Eq> Eq for NegIdxVec<T>
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> 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
Mutably borrows from an owned value. Read more