diff options
-rw-r--r-- | Cargo.toml | 3 | ||||
-rw-r--r-- | src/lib.rs | 142 | ||||
-rw-r--r-- | tests/schema-via-knuffel.rs | 2 |
3 files changed, 74 insertions, 73 deletions
@@ -6,7 +6,8 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [features] -default = ["knuffel"] +default = [] +parse-knuffel = ["knuffel"] [dependencies] knuffel = { version = "1.1.0", optional = true } @@ -1,118 +1,121 @@ -#[cfg(feature = "knuffel")] +#[cfg(feature = "parse-knuffel")] use knuffel::{Decode, DecodeScalar}; +mod schema_schema; +pub use schema_schema::SCHEMA_SCHEMA; + pub trait BuildFromRef { fn ref_to(query: impl Into<String>) -> Self; } #[derive(Debug, PartialEq, Eq, Default)] -#[cfg_attr(feature = "knuffel", derive(Decode))] +#[cfg_attr(feature = "parse-knuffel", derive(Decode))] pub struct Schema { - #[cfg_attr(feature = "knuffel", knuffel(child))] + #[cfg_attr(feature = "parse-knuffel", knuffel(child))] pub document: Document, } #[derive(Debug, PartialEq, Eq, Default)] -#[cfg_attr(feature = "knuffel", derive(Decode))] +#[cfg_attr(feature = "parse-knuffel", derive(Decode))] pub struct Document { - #[cfg_attr(feature = "knuffel", knuffel(child))] + #[cfg_attr(feature = "parse-knuffel", knuffel(child))] pub info: Info, - #[cfg_attr(feature = "knuffel", knuffel(children(name = "node")))] + #[cfg_attr(feature = "parse-knuffel", knuffel(children(name = "node")))] pub nodes: Vec<Node>, } #[derive(Debug, PartialEq, Eq, Default)] -#[cfg_attr(feature = "knuffel", derive(Decode))] +#[cfg_attr(feature = "parse-knuffel", derive(Decode))] pub struct Info { - #[cfg_attr(feature = "knuffel", knuffel(children(name = "title")))] + #[cfg_attr(feature = "parse-knuffel", knuffel(children(name = "title")))] pub title: Vec<TextValue>, - #[cfg_attr(feature = "knuffel", knuffel(children(name = "description")))] + #[cfg_attr(feature = "parse-knuffel", knuffel(children(name = "description")))] pub description: Vec<TextValue>, - #[cfg_attr(feature = "knuffel", knuffel(children(name = "author")))] + #[cfg_attr(feature = "parse-knuffel", knuffel(children(name = "author")))] pub authors: Vec<Person>, - #[cfg_attr(feature = "knuffel", knuffel(children(name = "contributor")))] + #[cfg_attr(feature = "parse-knuffel", knuffel(children(name = "contributor")))] pub contributors: Vec<Person>, - #[cfg_attr(feature = "knuffel", knuffel(children(name = "link")))] + #[cfg_attr(feature = "parse-knuffel", knuffel(children(name = "link")))] pub links: Vec<Link>, - #[cfg_attr(feature = "knuffel", knuffel(children(name = "license")))] + #[cfg_attr(feature = "parse-knuffel", knuffel(children(name = "license")))] pub licenses: Vec<License>, - #[cfg_attr(feature = "knuffel", knuffel(child))] + #[cfg_attr(feature = "parse-knuffel", knuffel(child))] pub published: Option<Date>, - #[cfg_attr(feature = "knuffel", knuffel(child))] + #[cfg_attr(feature = "parse-knuffel", knuffel(child))] pub modified: Option<Date>, } #[derive(Debug, PartialEq, Eq)] -#[cfg_attr(feature = "knuffel", derive(Decode))] +#[cfg_attr(feature = "parse-knuffel", derive(Decode))] pub struct TextValue { - #[cfg_attr(feature = "knuffel", knuffel(argument))] + #[cfg_attr(feature = "parse-knuffel", knuffel(argument))] pub text: String, - #[cfg_attr(feature = "knuffel", knuffel(property))] + #[cfg_attr(feature = "parse-knuffel", knuffel(property))] pub lang: Option<String>, } #[derive(Debug, PartialEq, Eq)] -#[cfg_attr(feature = "knuffel", derive(Decode))] +#[cfg_attr(feature = "parse-knuffel", derive(Decode))] pub struct Person { - #[cfg_attr(feature = "knuffel", knuffel(argument))] + #[cfg_attr(feature = "parse-knuffel", knuffel(argument))] pub name: String, - #[cfg_attr(feature = "knuffel", knuffel(property))] + #[cfg_attr(feature = "parse-knuffel", knuffel(property))] pub orcid: Option<String>, - #[cfg_attr(feature = "knuffel", knuffel(children(name = "link")))] + #[cfg_attr(feature = "parse-knuffel", knuffel(children(name = "link")))] pub links: Vec<Link>, } #[derive(Debug, PartialEq, Eq)] -#[cfg_attr(feature = "knuffel", derive(Decode))] +#[cfg_attr(feature = "parse-knuffel", derive(Decode))] pub struct Link { - #[cfg_attr(feature = "knuffel", knuffel(argument))] + #[cfg_attr(feature = "parse-knuffel", knuffel(argument))] pub iri: String, - #[cfg_attr(feature = "knuffel", knuffel(property))] + #[cfg_attr(feature = "parse-knuffel", knuffel(property))] pub rel: Option<String>, - #[cfg_attr(feature = "knuffel", knuffel(property))] + #[cfg_attr(feature = "parse-knuffel", knuffel(property))] pub lang: Option<String>, } #[derive(Debug, PartialEq, Eq)] -#[cfg_attr(feature = "knuffel", derive(Decode))] +#[cfg_attr(feature = "parse-knuffel", derive(Decode))] pub struct License { - #[cfg_attr(feature = "knuffel", knuffel(argument))] + #[cfg_attr(feature = "parse-knuffel", knuffel(argument))] pub name: String, - #[cfg_attr(feature = "knuffel", knuffel(property))] + #[cfg_attr(feature = "parse-knuffel", knuffel(property))] pub spdx: Option<String>, - #[cfg_attr(feature = "knuffel", knuffel(children(name = "link")))] + #[cfg_attr(feature = "parse-knuffel", knuffel(children(name = "link")))] pub link: Vec<Link>, } #[derive(Debug, PartialEq, Eq)] -#[cfg_attr(feature = "knuffel", derive(Decode))] +#[cfg_attr(feature = "parse-knuffel", derive(Decode))] pub struct Date { - #[cfg_attr(feature = "knuffel", knuffel(argument))] + #[cfg_attr(feature = "parse-knuffel", knuffel(argument))] pub date: String, - #[cfg_attr(feature = "knuffel", knuffel(property))] + #[cfg_attr(feature = "parse-knuffel", knuffel(property))] pub time: Option<String>, } #[derive(Debug, PartialEq, Eq, Default)] -#[cfg_attr(feature = "knuffel", derive(Decode))] +#[cfg_attr(feature = "parse-knuffel", derive(Decode))] pub struct Node { - #[cfg_attr(feature = "knuffel", knuffel(argument))] + #[cfg_attr(feature = "parse-knuffel", knuffel(argument))] pub name: Option<String>, - #[cfg_attr(feature = "knuffel", knuffel(property))] + #[cfg_attr(feature = "parse-knuffel", knuffel(property))] pub id: Option<String>, - #[cfg_attr(feature = "knuffel", knuffel(property))] + #[cfg_attr(feature = "parse-knuffel", knuffel(property))] pub description: Option<String>, - #[cfg_attr(feature = "knuffel", knuffel(property))] + #[cfg_attr(feature = "parse-knuffel", knuffel(property))] pub ref_: Option<String>, - #[cfg_attr(feature = "knuffel", knuffel(child, unwrap(argument)))] + #[cfg_attr(feature = "parse-knuffel", knuffel(child, unwrap(argument)))] pub min: Option<usize>, - #[cfg_attr(feature = "knuffel", knuffel(child, unwrap(argument)))] + #[cfg_attr(feature = "parse-knuffel", knuffel(child, unwrap(argument)))] pub max: Option<usize>, - #[cfg_attr(feature = "knuffel", knuffel(children(name = "prop")))] + #[cfg_attr(feature = "parse-knuffel", knuffel(children(name = "prop")))] pub props: Vec<Prop>, - #[cfg_attr(feature = "knuffel", knuffel(children(name = "value")))] + #[cfg_attr(feature = "parse-knuffel", knuffel(children(name = "value")))] pub values: Vec<Value>, - #[cfg_attr(feature = "knuffel", knuffel(children(name = "children")))] + #[cfg_attr(feature = "parse-knuffel", knuffel(children(name = "children")))] pub children: Vec<Children>, } @@ -126,19 +129,19 @@ impl BuildFromRef for Node { } #[derive(Debug, PartialEq, Eq, Default)] -#[cfg_attr(feature = "knuffel", derive(Decode))] +#[cfg_attr(feature = "parse-knuffel", derive(Decode))] pub struct Prop { - #[cfg_attr(feature = "knuffel", knuffel(argument))] + #[cfg_attr(feature = "parse-knuffel", knuffel(argument))] pub key: Option<String>, - #[cfg_attr(feature = "knuffel", knuffel(property))] + #[cfg_attr(feature = "parse-knuffel", knuffel(property))] pub id: Option<String>, - #[cfg_attr(feature = "knuffel", knuffel(property))] + #[cfg_attr(feature = "parse-knuffel", knuffel(property))] pub description: Option<String>, - #[cfg_attr(feature = "knuffel", knuffel(property))] + #[cfg_attr(feature = "parse-knuffel", knuffel(property))] pub ref_: Option<String>, - #[cfg_attr(feature = "knuffel", knuffel(child))] + #[cfg_attr(feature = "parse-knuffel", knuffel(child))] pub required: bool, - #[cfg_attr(feature = "knuffel", knuffel(children))] + #[cfg_attr(feature = "parse-knuffel", knuffel(children))] pub validations: Vec<Validation>, } @@ -152,19 +155,19 @@ impl BuildFromRef for Prop { } #[derive(Debug, PartialEq, Eq, Default)] -#[cfg_attr(feature = "knuffel", derive(Decode))] +#[cfg_attr(feature = "parse-knuffel", derive(Decode))] pub struct Value { - #[cfg_attr(feature = "knuffel", knuffel(property))] + #[cfg_attr(feature = "parse-knuffel", knuffel(property))] pub id: Option<String>, - #[cfg_attr(feature = "knuffel", knuffel(property))] + #[cfg_attr(feature = "parse-knuffel", knuffel(property))] pub description: Option<String>, - #[cfg_attr(feature = "knuffel", knuffel(property))] + #[cfg_attr(feature = "parse-knuffel", knuffel(property))] pub ref_: Option<String>, - #[cfg_attr(feature = "knuffel", knuffel(child, unwrap(argument)))] + #[cfg_attr(feature = "parse-knuffel", knuffel(child, unwrap(argument)))] pub min: Option<usize>, - #[cfg_attr(feature = "knuffel", knuffel(child, unwrap(argument)))] + #[cfg_attr(feature = "parse-knuffel", knuffel(child, unwrap(argument)))] pub max: Option<usize>, - #[cfg_attr(feature = "knuffel", knuffel(children))] + #[cfg_attr(feature = "parse-knuffel", knuffel(children))] pub validations: Vec<Validation>, } @@ -178,15 +181,15 @@ impl BuildFromRef for Value { } #[derive(Debug, PartialEq, Eq, Default)] -#[cfg_attr(feature = "knuffel", derive(Decode))] +#[cfg_attr(feature = "parse-knuffel", derive(Decode))] pub struct Children { - #[cfg_attr(feature = "knuffel", knuffel(property))] + #[cfg_attr(feature = "parse-knuffel", knuffel(property))] pub id: Option<String>, - #[cfg_attr(feature = "knuffel", knuffel(property))] + #[cfg_attr(feature = "parse-knuffel", knuffel(property))] pub description: Option<String>, - #[cfg_attr(feature = "knuffel", knuffel(property))] + #[cfg_attr(feature = "parse-knuffel", knuffel(property))] pub ref_: Option<String>, - #[cfg_attr(feature = "knuffel", knuffel(children(name = "node")))] + #[cfg_attr(feature = "parse-knuffel", knuffel(children(name = "node")))] pub nodes: Vec<Node>, } @@ -200,16 +203,16 @@ impl BuildFromRef for Children { } #[derive(Debug, PartialEq, Eq)] -#[cfg_attr(feature = "knuffel", derive(Decode))] +#[cfg_attr(feature = "parse-knuffel", derive(Decode))] pub enum Validation { - Type(#[cfg_attr(feature = "knuffel", knuffel(argument))] String), - Enum(#[cfg_attr(feature = "knuffel", knuffel(arguments))] Vec<String>), - Pattern(#[cfg_attr(feature = "knuffel", knuffel(argument))] String), - Format(#[cfg_attr(feature = "knuffel", knuffel(arguments))] Vec<Format>), + Type(#[cfg_attr(feature = "parse-knuffel", knuffel(argument))] String), + Enum(#[cfg_attr(feature = "parse-knuffel", knuffel(arguments))] Vec<String>), + Pattern(#[cfg_attr(feature = "parse-knuffel", knuffel(argument))] String), + Format(#[cfg_attr(feature = "parse-knuffel", knuffel(arguments))] Vec<Format>), } #[derive(Debug, PartialEq, Eq)] -#[cfg_attr(feature = "knuffel", derive(DecodeScalar))] +#[cfg_attr(feature = "parse-knuffel", derive(DecodeScalar))] pub enum Format { DateTime, Date, @@ -236,6 +239,3 @@ pub enum Format { Base64, KdlQuery, } - -mod schema_schema; -pub use schema_schema::SCHEMA_SCHEMA; diff --git a/tests/schema-via-knuffel.rs b/tests/schema-via-knuffel.rs index 147c905..24bba07 100644 --- a/tests/schema-via-knuffel.rs +++ b/tests/schema-via-knuffel.rs @@ -1,4 +1,4 @@ -#![cfg(feature = "knuffel")] +#![cfg(feature = "parse-knuffel")] use kdl_schema::{Schema, SCHEMA_SCHEMA}; |