Quickstart
[dependencies]
omnist = "0.0.1-alpha"
The shortest possible tour – one round trip, one schema, one validation,
one inference. Each snippet below is a trimmed version of a real file under
omnist/examples/; run it yourself with
cargo run --example <name>.
1. Read and write a document
#![allow(unused)]
fn main() {
use indexmap::IndexMap;
use omnist::document::{Doc, Value};
use omnist::formats::json::{read_json, write_json};
let mut fields = IndexMap::new();
fields.insert("name".to_string(), Value::Str("Ada".to_string()));
fields.insert("age".to_string(), Value::Int(37));
let doc = Doc::of(&Value::Object(fields)).unwrap();
let text = write_json(&doc, Some(2), true, None).unwrap();
// {
// "name": "Ada",
// "age": 37
// }
let doc2 = read_json(&text).unwrap();
assert!(doc.eq_doc(&doc2), "round trip must be lossless");
}
2. Validate against a schema
#![allow(unused)]
fn main() {
use omnist::osd::parse_schema;
let schema = parse_schema(
r#"record Person { "name": string, "age": integer } root Person"#,
).unwrap();
// schema.validate(&doc.root()).ok() == true for the document above
}
3. Infer a schema from example documents
#![allow(unused)]
fn main() {
use omnist::infer::infer;
use omnist::osd::to_osd;
let schema = infer(&samples, "Person").unwrap();
println!("{}", to_osd(&schema, Some(2)));
// record Person {
// "name": string,
// "age": integer,
// "tags" [0,]: string,
// }
// root Person
}
That’s it – a Doc, a Schema, validate(), and infer(). From here:
- User guide – the full practical tour, including formats and the CLI.
- CLI reference – the
omnistbinary’s command surface. - Per-format pages – adjustment/lossy-conversion behavior for JSON, YAML, TOML, XML, and OML.
- Limitations & stability – this port’s
0.0.xalpha status and known scoping gaps.