Trait CodeGen

Source
pub trait CodeGen: Debug + Clone {
    type Context;
    type Options;
    type SymbolTable;

    // Required method
    fn to_rust(
        self,
        ctx: Self::Context,
        options: Self::Options,
        symbols: Self::SymbolTable,
    ) -> Result<TokenStream, Box<dyn Error>>;

    // Provided methods
    fn find_symbols(self, symbols_in: Self::SymbolTable) -> Self::SymbolTable { ... }
    fn get_docstring(&self) -> Option<String> { ... }
}
Expand description

A trait for an object that can be converted to Rust code. Any data structure implementing this trait can be converted into a proc_macro2::TokenStream.

Required Associated Types§

Source

type Context

A type, generally an enum, that passes the code generator the context of the node.

Source

type Options

A struct representing the set of compilation options.

Source

type SymbolTable

A trait for a symbol table

Required Methods§

Source

fn to_rust( self, ctx: Self::Context, options: Self::Options, symbols: Self::SymbolTable, ) -> Result<TokenStream, Box<dyn Error>>

A trait method to output Rust code in a general sense. The output should be stream of Rust tokens, however, it is not guaranteed that it will fully compile because of scoping errors and other checks that don’t occur until later.

Provided Methods§

Source

fn find_symbols(self, symbols_in: Self::SymbolTable) -> Self::SymbolTable

A default implementation for find_symbols(), which simply returns the input. Language nodes that modify the symbol table should override this method.

Source

fn get_docstring(&self) -> Option<String>

A trait method for extracting a docstring from an object that can have a docstring.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§