Struct rustlr::generic_absyn::LBox

source ·
pub struct LBox<T: ?Sized> {
    pub exp: Box<T>,
    pub line: u32,
    pub column: u32,
    pub uid: u32,
}
Expand description

Custom smart pointer that encapsulates line and column numbers along with a regular Box. Implements Deref and DerefMut so the encapsulated expression can be accessed as in a standard Box. This is intended to to be used in the formation of abstract syntax trees so that the lexical information is available for each construct after the parsing stage. Also included in each LBox created by the runtime parser (ZCParser) is a 32 bit (u32) unique identifier uid that uniquely identifies each LBox. An expression and a subexpression can both begin at the same line and column numbers and the unique id would be required to distinguish them. This device is useful for hashing information, such as inferred types, based on the location of an expression in the source.

Fields§

§exp: Box<T>§line: u32§column: u32§uid: u32

Implementations§

source§

impl<T> LBox<T>

source

pub fn new(e: T, ln: usize, col: usize) -> LBox<T>

creates a new LBox with line ln, column col and uid set to zero; this function is deprecated by LBox::make.

source

pub fn make(e: T, ln: usize, col: usize, u: u32) -> LBox<T>

creates a new LBox enclosing e, with line ln, column col and uid u

source

pub fn transfer<U>(&self, e: U) -> LBox<U>

should be used to create a new LBoxed expression that inherits lexical information from existing LBox

source

pub fn line(&self) -> usize

Since version 0.2.4, Rustlr now stores the line and column information internally as u32 values instead of usize, and the LBox::line and LBox::column functions are provided for interface

source

pub fn column(&self) -> usize

source

pub fn uid(&self) -> u32

source§

impl<T: Default + ?Sized> LBox<T>

source

pub fn take(&mut self) -> T

replaces the boxed value with T::default() and returns the value

source

pub fn from_lc(c: LC<T>) -> Self

convert information from LC to LBox, consumes LC

source§

impl<'t> LBox<dyn Any + 't>

source

pub fn downcast<U: 't>(self) -> Option<LBox<U>>

emulates Box::downcast function, when LBox<dyn Any> is used as the abstract syntax type. Note that unlike Box::downcast, an Option is returned here instead of a result.

source

pub fn upcast<T: 't>(lb: LBox<T>) -> Self

do not try to create a LBox<dyn Any> structure with something like

 let lb:LBox<dyn Any> = LBox::new(String::from("abc"),0,0);

This does not work as LBox is simply borrowing the underlying mechanics of Box instead of re-creating them. Do instead:

 let lb:LBox<dyn Any> = LBox::upcast(LBox::new(String::from("abc"),0,0));

upcast always returns a LBox<dyn Any>.

Trait Implementations§

source§

impl<T: ?Sized> AsMut<T> for LBox<T>

source§

fn as_mut(&mut self) -> &mut T

Converts this type into a mutable reference of the (usually inferred) input type.
source§

impl<T: ?Sized> AsRef<T> for LBox<T>

source§

fn as_ref(&self) -> &T

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<T: Clone> Clone for LBox<T>

source§

fn clone(&self) -> Self

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 LBox<T>

source§

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

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

impl<T: Default> Default for LBox<T>

source§

fn default() -> Self

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

impl Default for LBox<dyn Any>

this is provided so LBox<dyn Any> can be used for the abstract syntax type. the default is a Lbox containing a static string.

source§

fn default() -> Self

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

impl<T> Deref for LBox<T>

§

type Target = T

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl<T> DerefMut for LBox<T>

source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.

Auto Trait Implementations§

§

impl<T: ?Sized> RefUnwindSafe for LBox<T>
where T: RefUnwindSafe,

§

impl<T: ?Sized> Send for LBox<T>
where T: Send,

§

impl<T: ?Sized> Sync for LBox<T>
where T: Sync,

§

impl<T: ?Sized> Unpin for LBox<T>

§

impl<T: ?Sized> UnwindSafe for LBox<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> 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> ToOwned for T
where T: Clone,

§

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>,

§

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>,

§

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.