TS

Trait TS 

Source
pub trait TS {
    // Required method
    fn typescript() -> TypeDef;
}
Expand description

The core trait for types that can be represented as TypeScript.

This is the foundation trait for ferrotype, similar to how Serialize is the foundation of serde. Implementations return a TypeDef that describes the TypeScript representation of the type.

§Design Philosophy

Unlike string-based approaches, returning a structured TypeDef enables:

  • Deduplication: Named types can be collected and emitted once
  • Analysis: Dependencies between types can be tracked
  • Flexibility: The IR can be rendered in different styles
  • Composition: Complex types build from simpler TypeDefs

§Example

use ferrotype::{TS, TypeDef, Primitive};

struct UserId(String);

impl TS for UserId {
    fn typescript() -> TypeDef {
        TypeDef::Named {
            namespace: vec![],
            name: "UserId".into(),
            def: Box::new(TypeDef::Primitive(Primitive::String)),
            module: None,
            wrapper: None,
        }
    }
}

Required Methods§

Source

fn typescript() -> TypeDef

Returns the TypeScript type definition for this type.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl TS for &str

Source§

impl TS for bool

Source§

impl TS for char

Source§

impl TS for f32

Source§

impl TS for f64

Source§

impl TS for i8

Source§

impl TS for i16

Source§

impl TS for i32

Source§

impl TS for i64

Source§

impl TS for i128

Source§

impl TS for isize

Source§

impl TS for u8

Source§

impl TS for u16

Source§

impl TS for u32

Source§

impl TS for u64

Source§

impl TS for u128

Source§

impl TS for ()

Source§

impl TS for usize

Source§

impl TS for String

Source§

impl<A: TS> TS for (A,)

Source§

impl<A: TS, B: TS> TS for (A, B)

Source§

impl<A: TS, B: TS, C: TS> TS for (A, B, C)

Source§

impl<A: TS, B: TS, C: TS, D: TS> TS for (A, B, C, D)

Source§

impl<A: TS, B: TS, C: TS, D: TS, E: TS> TS for (A, B, C, D, E)

Source§

impl<A: TS, B: TS, C: TS, D: TS, E: TS, F: TS> TS for (A, B, C, D, E, F)

Source§

impl<K: TS, V: TS> TS for BTreeMap<K, V>

Source§

impl<K: TS, V: TS> TS for HashMap<K, V>

Source§

impl<T: TS> TS for Option<T>

Source§

impl<T: TS> TS for Box<T>

Source§

impl<T: TS> TS for Rc<T>

Source§

impl<T: TS> TS for Arc<T>

Source§

impl<T: TS> TS for Vec<T>

Source§

impl<T: TS> TS for Cell<T>

Source§

impl<T: TS> TS for RefCell<T>

Source§

impl<T: TS, E: TS> TS for Result<T, E>

Implementors§