Skip to main content

Crate schema_bridge_lshape

Crate schema_bridge_lshape 

Source
Expand description

lshape exporter for schema-bridge.

Turns the schema-bridge Schema IR into lshape type definitions — a Lua module built from T.shape / T.array_of / T.one_of combinators that can be loaded and used with lshape.check.check.

use schema_bridge_core::{Field, Schema};
use schema_bridge_lshape::generate_lshape_file;

let user = Schema::Object(vec![
    Field::new("name", Schema::String),
    Field::optional("email", Schema::String),
]);
let lua_src = generate_lshape_file(&[("User", user)]).unwrap();
assert!(lua_src.contains("M.User = T.shape({"));

§lshape version requirement

Generated modules use T.integer / T.tuple / the bounds combinators (:min / :max / :min_len / :max_len), which require lshape 0.3.0+ at load time (vendored by mlua-lshape 0.3+).

Semantic note: lshape’s T.integer is the portable whole-number check (v % 1 == 0), so 2.0 passes; Rust-side integer range (e.g. u8) is not carried into the schema.

Macros§

export_lshape_types
Export types (anything deriving SchemaBridge) to an lshape Lua module.

Enums§

ExportError
Error produced by export_to_lua_file.
LshapeError
Error produced while mapping a Schema to lshape source text.

Functions§

export_to_lua_file
Generate the lshape module for types and write it to path.
generate_lshape_file
Generate a complete Lua module defining one lshape schema per entry.
schema_to_lshape
Convert a single Schema into an lshape expression such as T.shape({ name = T.string }).