| Crates.io | schematic |
| lib.rs | schematic |
| version | 0.18.12 |
| created_at | 2023-05-12 22:15:24.839743+00 |
| updated_at | 2025-07-26 17:12:48.761373+00 |
| description | A layered serde configuration and schema library. |
| homepage | https://moonrepo.github.io/schematic |
| repository | https://github.com/moonrepo/schematic |
| max_upload_size | |
| id | 863337 |
| size | 728,891 |
Schematic is a library that provides:
Both of these features can be used independently or together.
cargo add schematic
Get started: https://moonrepo.github.io/schematic
Define a struct or enum and derive the Config trait.
use schematic::Config;
#[derive(Config)]
struct AppConfig {
#[setting(default = 3000, env = "PORT")]
port: usize,
#[setting(default = true)]
secure: bool,
#[setting(default = vec!["localhost".into()])]
allowed_hosts: Vec<String>,
}
Then load, parse, merge, and validate the configuration from one or many sources. A source is either a file path, secure URL, or code block.
use schematic::{ConfigLoader, Format};
let result = ConfigLoader::<AppConfig>::new()
.code("secure: false", Format::Yaml)?
.file("path/to/config.yml")?
.url("https://ordomain.com/to/config.yaml")?
.load()?;
result.config;
result.layers;
Define a struct or enum and derive or implement the Schematic trait.
use schematic::Schematic;
#[derive(Schematic)]
struct Task {
command: String,
args: Vec<String>,
env: HashMap<String, String>,
}
Then generate output in multiple formats, like JSON schemas or TypeScript types, using the schema type information.
use schematic::schema::{SchemaGenerator, TypeScriptRenderer};
let mut generator = SchemaGenerator::default();
generator.add::<Task>();
generator.generate(output_dir.join("types.ts"), TypeScriptRenderer::default())?;