Struct ocaml_gen::Env

source ·
pub struct Env { /* private fields */ }
Expand description

The environment at some point in time during the declaration of OCaml bindings. It ensures that types cannot be declared twice, and that types that are renamed and/or relocated into module are referenced correctly.

Implementations§

source§

impl Env

source

pub fn new() -> Self

Creates a new environment.

source

pub fn new_type(&mut self, ty: u128, name: &'static str)

Declares a new type. If the type was already declared, this will panic.

Panics

The function will panic if the type was already declared.

source

pub fn get_type(&self, ty: u128, name: &str) -> (String, bool)

Retrieves a type that was declared previously. A boolean indicates if the type is being aliased.

Panics

The function will panic if the type was not declared previously.

source

pub fn add_alias(&mut self, ty: u128, alias: &'static str)

Adds a new alias for the current scope (module).

Panics

The function will panic if the alias was already declared.

source

pub fn new_module(&mut self, mod_name: &'static str) -> String

Create a module and enters it.

Panics

This function will panic if the module was already declared, or if the module name is not following the OCaml guidelines.

source

pub fn nested(&self) -> usize

how deeply nested are we currently? (default is 0)

source

pub fn parent(&mut self) -> String

called when we exit a module

source

pub fn root(&mut self) -> String

you can call this to go back to the root and finalize the generation

Trait Implementations§

source§

impl Debug for Env

source§

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

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

impl Default for Env

source§

fn default() -> Self

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

impl Drop for Env

source§

fn drop(&mut self)

This makes sure that we close our OCaml modules (with the keyword end).

Auto Trait Implementations§

§

impl RefUnwindSafe for Env

§

impl Send for Env

§

impl Sync for Env

§

impl Unpin for Env

§

impl UnwindSafe for Env

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

§

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.