Skip to main content

RustRenderer

Struct RustRenderer 

Source
pub struct RustRenderer { /* private fields */ }
Expand description

Rust code generator that converts IR to idiomatic Rust code

This generator implements the CodeGenerator trait and produces clean, well-formatted Rust code with proper derives and attributes.

§Features

  • Derive Macros: Automatically adds Debug, Clone, PartialEq, and optional serde derives
  • Nested Types: Generates all nested struct definitions
  • Documentation: Preserves doc comments from IR
  • Formatting: Produces properly indented, formatted code
  • Type Safety: Maps IR types to appropriate Rust types

§Examples

use unistructgen_codegen::{RustRenderer, RenderOptions};
use unistructgen_core::{CodeGenerator, IRModule, IRStruct, IRType};

let mut module = IRModule::new("User".to_string());
let user_struct = IRStruct::new("User".to_string());
module.add_type(IRType::Struct(user_struct));

let renderer = RustRenderer::new(RenderOptions::default());
let code = renderer.generate(&module).expect("Failed to generate");
assert!(code.contains("pub struct User"));

Implementations§

Source§

impl RustRenderer

Source

pub fn builder() -> RustRendererBuilder

Create a builder for configuring a RustRenderer

This is a convenience method that returns a new builder.

§Examples
use unistructgen_codegen::RustRenderer;

let renderer = RustRenderer::builder()
    .minimal()
    .build();
Source§

impl RustRenderer

Source

pub fn new(options: RenderOptions) -> Self

Source

pub fn render(&self, module: &IRModule) -> Result<String>

Trait Implementations§

Source§

impl CodeGenerator for RustRenderer

Source§

type Error = CodegenError

The error type this generator produces
Source§

fn generate(&self, module: &IRModule) -> Result<String, Self::Error>

Generate code from an IR module Read more
Source§

fn language(&self) -> &'static str

Get the target language name Read more
Source§

fn file_extension(&self) -> &str

Get the file extension for generated code Read more
Source§

fn validate(&self, module: &IRModule) -> Result<(), Self::Error>

Validate IR before generation (optional) Read more
Source§

fn format(&self, code: String) -> Result<String, Self::Error>

Format generated code (optional) Read more
Source§

fn metadata(&self) -> GeneratorMetadata

Get metadata about the generator (optional) Read more

Auto Trait Implementations§

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<G> CodeGeneratorExt for G
where G: CodeGenerator,

Source§

fn generate_formatted(&self, module: &IRModule) -> Result<String, Self::Error>

Generate and format code in one step
Source§

fn generate_validated(&self, module: &IRModule) -> Result<String, Self::Error>

Generate code with validation first
Source§

fn generate_complete(&self, module: &IRModule) -> Result<String, Self::Error>

Generate, validate, and format code
Source§

fn generate_or<E>(&self, module: &IRModule) -> Result<String, E>
where E: From<Self::Error>,

Generate code and convert to a specific error type
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>,

Source§

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

Source§

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.