pub struct TypeRegistry { /* private fields */ }Expand description
A registry for collecting and managing TypeScript type definitions.
The TypeRegistry collects named types, resolves their dependency order, and renders them to a TypeScript file. This enables:
- Deduplication: Each named type is emitted once
- Ordering: Types are emitted in dependency order
- Output: Generate valid .ts or .d.ts files
§Example
ⓘ
use ferrotype::{TypeRegistry, TypeScript};
let mut registry = TypeRegistry::new();
registry.register::<User>();
registry.register::<Post>();
let output = registry.render();
std::fs::write("types.ts", output)?;Implementations§
Source§impl TypeRegistry
impl TypeRegistry
Sourcepub fn register<T: TypeScript>(&mut self)
pub fn register<T: TypeScript>(&mut self)
Registers a type that implements TypeScript.
This extracts all named types from the type definition and adds them to the registry. Named types are deduplicated by name.
Sourcepub fn add_typedef(&mut self, typedef: TypeDef)
pub fn add_typedef(&mut self, typedef: TypeDef)
Adds a TypeDef to the registry, extracting all named types.
Sourcepub fn type_names(&self) -> impl Iterator<Item = &str>
pub fn type_names(&self) -> impl Iterator<Item = &str>
Returns the names of all registered types.
Sourcepub fn sorted_types(&self) -> Vec<&str>
pub fn sorted_types(&self) -> Vec<&str>
Returns types in dependency order (types with no dependencies first).
Uses Kahn’s algorithm for topological sort.
Sourcepub fn render(&self) -> String
pub fn render(&self) -> String
Renders all registered types to TypeScript declarations.
Types are emitted in dependency order, with proper formatting.
Sourcepub fn render_exported(&self) -> String
pub fn render_exported(&self) -> String
Renders all registered types with export keywords.
Trait Implementations§
Source§impl Debug for TypeRegistry
impl Debug for TypeRegistry
Source§impl Default for TypeRegistry
impl Default for TypeRegistry
Source§fn default() -> TypeRegistry
fn default() -> TypeRegistry
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for TypeRegistry
impl RefUnwindSafe for TypeRegistry
impl Send for TypeRegistry
impl Sync for TypeRegistry
impl Unpin for TypeRegistry
impl UnwindSafe for TypeRegistry
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more