Expand description
§kdl-schema
KDL Schema types and parsing.
§examples
§building a schema
use kdl_schema::*;
let schema = Schema {
document: Document {
info: Info {
title: vec![TextValue {
text: "Sample Schema".to_string(),
lang: Some("en".to_string()),
}],
..Info::default()
},
nodes: vec![Node {
name: Some("name".to_string()),
values: vec![Value {
validations: vec![Validation::Type("string".to_string())],
..Value::default()
}],
..Node::default()
}]
}
};
println!("{:?}", schema);
§parsing a schema KDL
#[cfg(feature = "parse-knuffel")] {
let schema_kdl = r#"
document {
info {
title "Sample Schema" lang="en"
description "An example schema" lang="en"
author "boringcactus"
}
node "name" {
value {
type "string"
}
}
node "age" {
value {
type "number"
}
}
}
"#;
let _matching_document = r#"
name "Joe"
age 69
"#;
let schema = kdl_schema::Schema::parse(schema_kdl).unwrap();
assert_eq!(schema.document.info.title[0].text, "Sample Schema");
}
§referencing the schema schema
assert_eq!(kdl_schema::SCHEMA_SCHEMA.document.info.title[0].text, "KDL Schema");
§cargo features
parse-knuffel
- exposeSchema::parse
, powered by theknuffel
crate
§conditions blocking version 1.0.0
- consistently good documentation
- merge ref target over ref source if ref source has anything else
- good API for parsing from a file
- types actually match the schema (currently I’m omitting several things because the schema schema doesn’t use them)
- ergonomic builder API to define a schema in Rust in a non-ugly way
- can generate KDL from schema object in Rust
- can choose kdl or knuffel as parser
- make sure
required false
in aprop
works properly - validate the schema at parse time (ensure that e.g. refs are resolvable, IDs are unique)
- make sure enums work with int values
- allow rich types for language tags, modification dates, etc
§license
Re-exports§
pub use schema_schema::SCHEMA_SCHEMA;
Structs§
- Children
- schema for a node’s children
- Date
- date with optional time
- Document
- the schema document
- Info
- schema metadata
- License
- schema license information
- Link
- link related to specification metadata, with optional relationship and language tag
- Node
- schema for a node
- Person
- information about a schema author/contributor
- Prop
- schema for a property
- SCHEMA_
SCHEMA - the schema schema defined by the canonical
kdl-schema.kdl
- Schema
- the schema itself
- Text
Value - a text value with an optional language tag
- Value
- schema for a value
Enums§
- Format
- a format to ensure a value has
- Validation
- a validation to apply to some value or property value