10 releases

0.1.9 Apr 14, 2024
0.1.8 Apr 14, 2024
0.1.7 Dec 27, 2023

#726 in Development tools

Download history 1/week @ 2024-07-26 21/week @ 2024-09-20 19/week @ 2024-09-27

475 downloads per month
Used in fluorite_codegen

MIT/Apache

9KB
175 lines

Fluorite

Crates.io docs.rs

Generate rust/typescript codes from schemas specified by Yaml/JSON.

The Fluorite Schema definition code is generated by fluorite rust -i src/fluorite/definition.yaml -o ./src/definitions/.

Using fluorite in a Cargo Project

Please check the demo project for details. Add following dependencies first:

[dependencies]
serde = "<serde-version>"
fluorite = "0.1"
derive-new = "0.6"

[build-dependencies]
fluorite_codegen = "0.1"

Using fluorite in the build.rs to generate codes during the Cargo build process:

fn main() {
    let out_dir = std::env::var("OUT_DIR").unwrap();
    fluorite::compile(&["fluorite/demo.yaml"], out_dir.as_str()).unwrap();
}

Instruct your project to include the generated codes, e.g. in your lib or main file:

mod demo {
    include!(concat!(env!("OUT_DIR"), "/demo/mod.rs"));
}

Using fluorite as a cli

$ fluorite --help
Generate rust/typescript codes from schemas specified by Yaml/JSON.

Usage: fluorite [OPTIONS] --output <OUTPUT>

Options:
  -i, --inputs <INPUTS>  Input definition files
  -o, --output <OUTPUT>  Output directory
  -t, --target <TARGET>  Target language [default: rust] [possible values: rust]
  -h, --help             Print help
  -V, --version          Print version

Features

  • Supports Yaml schema definition, see example here
  • A codegen binary program
  • Language Support
    • Rust codegen used in Cargo build.rs script
    • Typescript codegen
    • CodeGen API to add more language supports to fluorite
  • Support for JSON schema definition (no plan)

Schema Definition Features

More details can be found in definitions.rs.

  • User defined types:
    • Object
    • Enum
    • ObjectEnum: to support polymorphic types during serialization/deserialization
  • Collection types:
    • List
    • Map
  • Primitive types
    • String
    • Bool
    • (WIP) DateTime
    • UIntX
    • IntX
    • Float
  • Optional fields support
  • Any type fields support

Dependencies

~0.4–1MB
~22K SLoC