TypeMapper

Trait TypeMapper 

Source
pub trait TypeMapper {
    // Required methods
    fn map_primitive(&self, ty: PrimitiveType) -> String;
    fn map_optional(&self, inner: &str) -> String;
    fn map_array(&self, inner: &str) -> String;
    fn map_result(&self, ok: &str, err: &str) -> String;
    fn map_unit(&self) -> String;

    // Provided methods
    fn map_ref(&self, inner: &str) -> String { ... }
    fn map_ref_mut(&self, inner: &str) -> String { ... }
    fn map_generic(&self, base: &str, args: &[String]) -> String { ... }
    fn render_type(&self, ty: &TypeRef) -> String { ... }
}
Expand description

Trait for mapping types to language-specific representations.

Implement this trait to support a new target language’s type system.

Required Methods§

Source

fn map_primitive(&self, ty: PrimitiveType) -> String

Map a primitive type to the target language.

Source

fn map_optional(&self, inner: &str) -> String

Map an optional type (e.g., Option<T>, T | undefined).

Source

fn map_array(&self, inner: &str) -> String

Map an array type (e.g., Vec<T>, T[]).

Source

fn map_result(&self, ok: &str, err: &str) -> String

Map a Result type (Rust: Result<T, E>, TS: T, Go: (T, error)).

Source

fn map_unit(&self) -> String

Map the unit type (Rust: (), TS: void, Go: empty).

Provided Methods§

Source

fn map_ref(&self, inner: &str) -> String

Map a reference type (Rust: &T, others usually no-op).

Source

fn map_ref_mut(&self, inner: &str) -> String

Map a mutable reference type (Rust: &mut T).

Source

fn map_generic(&self, base: &str, args: &[String]) -> String

Map a generic type with arguments.

Source

fn render_type(&self, ty: &TypeRef) -> String

Render a complete TypeRef to a string.

Implementors§