Skip to main content

Crate typespec_rs

Crate typespec_rs 

Source
Expand description

§typespec-rs

A Rust implementation of the TypeSpec type system — parser, type checker, and emitter.

This is an independent Rust port of the TypeSpec compiler, not a binding to the TypeScript compiler. It implements the parser, checker, and emitter pipeline natively in Rust.

§Quick Start

use typespec_rs::emit::{to_yaml, to_json};

let src = r#"
    model Pet {
        id: string;
        name: string;
        age?: int32;
    }
"#;

let yaml = to_yaml(src).unwrap();
let json = to_json(src).unwrap();

§Module Organization

  • emit — Convert TypeSpec to YAML/JSON output (primary user-facing API)
  • parser — Parse TypeSpec source into AST
  • checker — Type checking and semantic analysis
  • ast — AST node types

Internal modules (#[doc(hidden)]) are used by the compiler pipeline but are not part of the stable public API.

§Status

This project is in early development. The scanner, parser, and core type checker are functional. See the repository for the latest status.

Modules§

ast
Abstract Syntax Tree types for TypeSpec.
checker
TypeSpec Checker - Core type checking for TypeSpec-Rust Ported from TypeSpec compiler/src/core/checker.ts
code_fixes
Code fix utilities for TypeSpec-Rust
diagnostics
Diagnostics module for TypeSpec-Rust
emit
TypeSpec Emit API
libs
TypeSpec Library Modules
mime_type
MIME type utilities for TypeSpec-Rust
param_message
Param message utilities for TypeSpec-Rust
parser
TypeSpec Parser implementation
path_utils
Path utilities for TypeSpec-Rust
perf
Performance timing utilities for TypeSpec-Rust
source_file
Source file utilities for TypeSpec-Rust
utils
Utility data structures and functions

Macros§

flag_decorator
Generate a flag decorator (apply + is pair).
numeric_decorator
Generate a numeric decorator (apply + get pair).
optional_name_decorator
Generate an optional-name decorator (apply + is + get_name triple).
string_decorator
Generate a string decorator (apply + get pair).
string_enum
Generate an enum with as_str() and parse_str() methods.
typeid_decorator
Generate a TypeId decorator (apply + get pair).
visibility_decorator
Generate a visibility decorator (apply + get pair for comma-separated modifiers).