83 lines
1.9 KiB
Markdown
83 lines
1.9 KiB
Markdown
# Decodal
|
|
|
|
Decodal is a small deterministic DSL for describing, composing, validating, and materializing structured data.
|
|
|
|
It is designed around a lightweight Rust library:
|
|
|
|
- host-supplied imports through `SourceLoader`
|
|
- no filesystem access in the library core
|
|
- concrete and abstract values with constraints and defaults
|
|
- deterministic expression evaluation
|
|
- optional regex support behind a Cargo feature
|
|
- browser playground support through WebAssembly
|
|
|
|
## Library crate
|
|
|
|
Embedded hosts should depend on `decodal` and provide imports with a `SourceLoader`.
|
|
|
|
```toml
|
|
[dependencies]
|
|
decodal = "0.1"
|
|
```
|
|
|
|
## Derive support
|
|
|
|
For embedded Rust applications, Decodal can generate a schema and typed decoder from a Rust struct with the `derive` feature.
|
|
|
|
```toml
|
|
[dependencies]
|
|
decodal = { version = "0.1", features = ["derive"] }
|
|
```
|
|
|
|
```rust
|
|
use decodal::{Decodal, DecodalDecode, DecodalSchema, Engine};
|
|
|
|
#[derive(Decodal)]
|
|
struct Service {
|
|
name: String,
|
|
#[decodal(gt = 443, default = 8443)]
|
|
port: i64,
|
|
#[decodal(rename = "feature.enable", default = true)]
|
|
feature_enabled: bool,
|
|
}
|
|
```
|
|
|
|
The derive implements:
|
|
|
|
- `DecodalSchema`, which produces a host schema for `Engine::bind_global`
|
|
- `DecodalDecode`, which converts materialized `Data` into the Rust struct
|
|
|
|
## CLI
|
|
|
|
A standalone CLI is kept in this repository as the `decodal-cli` workspace package.
|
|
It builds a `decodal` binary, but it is not the primary crates.io package.
|
|
|
|
Run a Decodal file from the repository:
|
|
|
|
```sh
|
|
cargo run -q -p decodal-cli -- examples/advanced/main.dcdl
|
|
```
|
|
|
|
Enable optional regex support when needed:
|
|
|
|
```sh
|
|
cargo run -q -p decodal-cli --features regex -- examples/regex/main.dcdl
|
|
```
|
|
|
|
## Web playground
|
|
|
|
The static documentation site and browser playground live under:
|
|
|
|
```text
|
|
site/decodal-site/
|
|
```
|
|
|
|
## License
|
|
|
|
Licensed under either of:
|
|
|
|
- Apache License, Version 2.0
|
|
- MIT license
|
|
|
|
at your option.
|