Skip to main content

TypeScriptMapper

Struct TypeScriptMapper 

Source
pub struct TypeScriptMapper {
    pub readonly: bool,
    pub file_style: FileStyle,
}
Expand description

TypeScript language mapper.

Generates TypeScript interfaces from Rust structs and discriminated unions from enums.

Fields§

§readonly: bool

Whether all fields should be readonly

§file_style: FileStyle

File naming style (default: kebab-case)

Implementations§

Source§

impl TypeScriptMapper

Source

pub fn new() -> Self

Source

pub fn with_readonly(self, readonly: bool) -> Self

Source

pub fn with_file_style(self, style: FileStyle) -> Self

Trait Implementations§

Source§

impl Default for TypeScriptMapper

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl TypeMapper for TypeScriptMapper

Source§

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

Map a Rust primitive type to the target language’s equivalent. Read more
Source§

fn map_option(&self, inner: &TypeKind) -> String

Map an Option<T> type to the target language. Read more
Source§

fn map_vec(&self, inner: &TypeKind) -> String

Map a Vec<T> type to the target language. Read more
Source§

fn map_hashmap(&self, key: &TypeKind, value: &TypeKind) -> String

Map a HashMap<K, V> type to the target language. Read more
Source§

fn map_tuple(&self, elements: &[TypeKind]) -> String

Map a tuple type (A, B, ...) to the target language.
Source§

fn map_named(&self, name: &str) -> String

Map a named custom type (reference to another struct or enum). Read more
Source§

fn emit_struct(&self, def: &StructDef) -> String

Render a complete struct as target language source code.
Source§

fn emit_enum(&self, def: &EnumDef) -> String

Render a complete enum as target language source code.
Source§

fn file_header(&self, type_name: &str) -> String

File header content (auto-generated comment, import statements, pragmas).
Source§

fn file_extension(&self) -> &str

File extension for the output file (without the leading dot).
Source§

fn emit_imports(&self, def: &TypeDef) -> String

Generate import statements for types referenced by this type definition. Read more
Source§

fn file_naming(&self, type_name: &str) -> String

Naming convention for output files. Read more
File footer content (if needed). Default: empty.
Source§

fn map_generic(&self, name: &str, params: &[TypeKind]) -> String

Map a generic type Name<A, B> to the target language. Read more
Source§

fn map_type(&self, ty: &TypeKind) -> String

Map any TypeKind to the target language string. Read more
Source§

fn emit_type_def(&self, def: &TypeDef) -> String

Emit a complete TypeDef (struct or enum) as target language source code. Read more
Source§

fn output_filename(&self, type_name: &str) -> String

Get the full output filename for a type.

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