Struct Scope

Source
pub struct Scope<K: Hash + Eq, V>(/* private fields */);
Expand description

Structure for storing an AST node as a hashmap node inside of a vector.

To use this structure, a node type has to implament Hash and Eq (similar to PartialEq).

Implementations§

Source§

impl<K: Hash + Eq, V> Scope<K, V>

Source

pub fn new() -> Self

Creates a new, empty scope.

Source

pub fn enter_scope(&mut self)

Creates a new scope at top of stack, acting as a new scope.

Source

pub fn leave_scope(&mut self)

Leaves the scope by popping the top value of the HashMap vector stack.

Source

pub fn get(&self, item: &K) -> Option<&V>

Scans bottom-up from the scope stack to find the specified item argument. This method recurses down the branches of the stack until it finds the item (linear search).

Source

pub fn insert(&mut self, key: K, value: V) -> Option<V>

Inserts a new item into the stack.

NOTE: This will panic if a fatal error occurs if inserting into a broken stack.

Source

pub fn depth(&self) -> usize

Gets the depth of the entire Scope data structure.

Auto Trait Implementations§

§

impl<K, V> Freeze for Scope<K, V>

§

impl<K, V> RefUnwindSafe for Scope<K, V>

§

impl<K, V> Send for Scope<K, V>
where K: Send, V: Send,

§

impl<K, V> Sync for Scope<K, V>
where K: Sync, V: Sync,

§

impl<K, V> Unpin for Scope<K, V>
where K: Unpin, V: Unpin,

§

impl<K, V> UnwindSafe for Scope<K, V>
where K: UnwindSafe, V: 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> 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<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.