|
1 | 1 | # typia |
2 | 2 |
|
3 | | -`typia` is a scaffold-stage Rust project for type-safe JSON schema validation. |
| 3 | +`typia` provides serde-based LLM JSON utilities for Rust. |
4 | 4 |
|
5 | | -## Goal and Current Status |
| 5 | +## Stable APIs |
6 | 6 |
|
7 | | -- Goal: provide a stable runtime foundation for type-safe validation and schema workflows. |
8 | | -- Current status: scaffold only; the crate does not expose stabilized public APIs yet. |
9 | | -- API policy: v0 public function/type and macro identifiers are intentionally not frozen at this stage. |
| 7 | +- `LLMData` trait |
| 8 | + - `parse(input: &str) -> LlmJsonParseResult<Self>` |
| 9 | + - `validate(value: serde_json::Value) -> Result<Self, serde_json::Error>` |
| 10 | + - `stringify(&self) -> Result<String, serde_json::Error>` |
| 11 | +- `LlmJsonParseResult<T>` |
| 12 | +- `LlmJsonParseError` |
| 13 | +- `#[derive(LLMData)]` (from `typia-macros`, re-exported by `typia`) |
10 | 14 |
|
11 | | -## Component Architecture |
| 15 | +## Example |
12 | 16 |
|
13 | | -- `core`: `crates/typia` (active scaffold) |
14 | | -- `macros`: `crates/typia-macros` (active scaffold) |
| 17 | +```rust |
| 18 | +use typia::{ |
| 19 | + LLMData, |
| 20 | + serde::{Deserialize, Serialize}, |
| 21 | +}; |
15 | 22 |
|
16 | | -Future macro-generated code must remain compatible with the core runtime contracts. |
| 23 | +#[derive(Debug, Serialize, Deserialize, LLMData)] |
| 24 | +struct User { |
| 25 | + id: u32, |
| 26 | + name: String, |
| 27 | +} |
17 | 28 |
|
18 | | -## Current Non-Goals |
| 29 | +fn main() { |
| 30 | + let parsed = User::parse("{id: 1, name: \"alice\",}"); |
| 31 | + println!("{parsed:?}"); |
| 32 | +} |
| 33 | +``` |
| 34 | + |
| 35 | +## Lenient Parser Behaviors |
| 36 | + |
| 37 | +`LLMData::parse()` uses typia's internal lenient JSON parser before serde validation. |
| 38 | + |
| 39 | +Supported recovery behaviors: |
19 | 40 |
|
20 | | -- Freezing public runtime API identifiers before scaffold-stage contracts are finalized. |
21 | | -- Defining stable derive macro names or expansion schemas before macro interface contracts are stabilized. |
22 | | -- Providing production-ready validation semantics before core and macro contracts are documented as active. |
| 41 | +- markdown ` ```json ... ``` ` extraction |
| 42 | +- junk prefix skipping before JSON payloads |
| 43 | +- JavaScript comments (`//`, `/* ... */`) |
| 44 | +- unquoted object keys |
| 45 | +- trailing commas |
| 46 | +- partial keywords (`tru`, `fal`, `nul`) |
| 47 | +- unclosed strings/brackets with partial recovery |
| 48 | +- unicode escapes (including surrogate-pair decoding) |
| 49 | +- depth guard (`MAX_DEPTH = 512`) |
23 | 50 |
|
24 | 51 | ## Local Validation |
25 | 52 |
|
|
0 commit comments