Trait python_ast::codegen::CodeGen
source · pub trait CodeGen: Debug {
type Context;
type Options;
// Required method
fn to_rust(
self,
ctx: Self::Context,
options: Self::Options
) -> Result<TokenStream, Box<dyn Error>>;
// Provided method
fn get_docstring(&self) -> Option<String> { ... }
}
Expand description
Reexport the CodeGen from to_tokenstream 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§
Required Methods§
sourcefn to_rust(
self,
ctx: Self::Context,
options: Self::Options
) -> Result<TokenStream, Box<dyn Error>>
fn to_rust( self, ctx: Self::Context, options: Self::Options ) -> 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§
sourcefn get_docstring(&self) -> Option<String>
fn get_docstring(&self) -> Option<String>
A trait method for extracting a docstring from an object that can have a docstring.
Implementors§
source§impl CodeGen for ClassDef
impl CodeGen for ClassDef
type Context = CodeGenContext
type Options = PythonOptions
source§impl CodeGen for Constant
impl CodeGen for Constant
type Context = CodeGenContext
type Options = PythonOptions
source§impl CodeGen for Import
impl CodeGen for Import
An Import (or FromImport) statement causes 2 things to occur:
- Declares the imported object within the existing scope.
- Causes the referenced module to be compiled into the program (only once).