charon_lib::ast::types::vars

Struct BindingStack

source
pub struct BindingStack<T> {
    stack: Vec<T>,
}
Expand description

A stack of values corresponding to nested binders. Each binder introduces an entry in this stack, with the entry as index 0 being the innermost binder. This is indexed by DeBruijnIds. Most methods assume that the stack is non-empty and panic if not.

Fields§

§stack: Vec<T>

The stack, stored in reverse. We push/pop to the end of the Vec, and the last pushed value (i.e. the end of the vec) is considered index 0.

Implementations§

source§

impl<T> BindingStack<T>

source

pub fn new(x: T) -> Self

source

pub fn is_empty(&self) -> bool

source

pub fn len(&self) -> usize

source

pub fn depth(&self) -> DeBruijnId

source

pub fn as_bound_var<Id>(&self, var: DeBruijnVar<Id>) -> (DeBruijnId, Id)

Map a bound variable to ids binding depth.

source

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

source

pub fn pop(&mut self) -> Option<T>

source

fn real_index(&self, id: DeBruijnId) -> Option<usize>

Helper that computes the real index into self.stack.

source

pub fn get(&self, id: DeBruijnId) -> Option<&T>

source

pub fn get_var<'a, Id: Idx, Inner>( &'a self, var: DeBruijnVar<Id>, ) -> Option<&'a Inner::Output>
where T: Borrow<Inner>, Inner: HasVectorOf<Id> + 'a,

source

pub fn get_mut(&mut self, id: DeBruijnId) -> Option<&mut T>

source

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

Iterate over the binding levels, from the innermost (0) out.

source

pub fn iter_enumerated( &self, ) -> impl Iterator<Item = (DeBruijnId, &T)> + DoubleEndedIterator + ExactSizeIterator

Iterate over the binding levels, from the innermost (0) out.

source

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

source

pub fn innermost(&self) -> &T

source

pub fn innermost_mut(&mut self) -> &mut T

source

pub fn outermost(&self) -> &T

source

pub fn outermost_mut(&mut self) -> &mut T

Trait Implementations§

source§

impl<T: Clone> Clone for BindingStack<T>

source§

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

source§

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

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

impl<T> Default for BindingStack<T>

source§

fn default() -> Self

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

impl<T: Hash> Hash for BindingStack<T>

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<T> Index<DeBruijnId> for BindingStack<T>

source§

type Output = T

The returned type after indexing.
source§

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

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

impl<T> IndexMut<DeBruijnId> for BindingStack<T>

source§

fn index_mut(&mut self, id: DeBruijnId) -> &mut Self::Output

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

Auto Trait Implementations§

§

impl<T> Freeze for BindingStack<T>

§

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

§

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

§

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

§

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

§

impl<T> UnwindSafe for BindingStack<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<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<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