Trait code_generator::CodeGenerate

source ·
pub trait CodeGenerate {
    // Required method
    fn generate(
        &self,
        f: &mut Formatter<'_>,
        info: CodeGenerationInfo,
    ) -> Result;
}

Required Methods§

source

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

Trait function which allows the generation of code with context

§Example Implementation
struct Example {
    a: u32,
}
 
impl CodeGenerate for Example {
    fn generate(&self, f: &mut fmt::Formatter<'_>, info: CodeGenerationInfo) -> fmt::Result {
        write!(f, "{}", self.a)
    }
}
 
let example = Example {a: 69};
let info = CodeGenerationInfo::from_style(CodeStyle::KnR);
assert_eq!("69", format!("{}", example.display(info)));

Implementations on Foreign Types§

source§

impl CodeGenerate for String

Raw code with no formatting besides injecting newlines, and indentation based on the context

source§

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

Implementors§