diff --git a/implementations/rust/preserves-schema/src/compiler/types.rs b/implementations/rust/preserves-schema/src/compiler/types.rs index 7fb0f40..6259bca 100644 --- a/implementations/rust/preserves-schema/src/compiler/types.rs +++ b/implementations/rust/preserves-schema/src/compiler/types.rs @@ -152,19 +152,19 @@ pub fn render_field_type(box_needed: bool, t: &TField) -> impl Emittable { pub fn render_recordlike_type(is_struct: bool, n: &str, d: &TSimple) -> impl Emittable { let semi = if is_struct { seq![";"] } else { seq![] }; + let ppub = if is_struct { "pub " } else { "" }; seq![names::render_constructor(n), match d { TSimple::Record(TRecord(fs)) => seq![" ", braces( fs.iter().map(|(n, d)| item( - seq![if is_struct { "pub " } else { "" }, - names::render_fieldname(n), ": ", render_field_type(true, d)] + seq![ppub, names::render_fieldname(n), ": ", render_field_type(true, d)] )).collect())], TSimple::Field(TField::Unit) => semi, - TSimple::Field(t) => seq![parens![render_field_type(true, t)], semi], + TSimple::Field(t) => seq![parens![seq![ppub, render_field_type(true, t)]], semi], }] } pub fn render_definition_type(n: &str, t: &TDefinition) -> impl Emittable { - seq!["#[derive(Debug, PartialOrd, Ord, PartialEq, Eq)] ", + seq!["#[derive(Debug, PartialOrd, Ord, PartialEq, Eq)]\n", match t { TDefinition::Union(items) => seq!["pub enum ", names::render_constructor(n), " ", braces( diff --git a/implementations/rust/preserves-schema/src/metaschema.rs b/implementations/rust/preserves-schema/src/metaschema.rs index 0d58b0b..983206a 100644 --- a/implementations/rust/preserves-schema/src/metaschema.rs +++ b/implementations/rust/preserves-schema/src/metaschema.rs @@ -36,13 +36,17 @@ lazy_static! { pub static ref LIT20: preserves::value::IOValue = /* version */ preserves::value::PackedReader::decode_bytes(&vec![179, 7, 118, 101, 114, 115, 105, 111, 110]).demand_next(false).unwrap(); } -#[derive(Debug, PartialOrd, Ord, PartialEq, Eq)] pub enum AtomKind {Boolean, Float, Double, SignedInteger, String, ByteString, Symbol} +#[derive(Debug, PartialOrd, Ord, PartialEq, Eq)] +pub enum AtomKind {Boolean, Float, Double, SignedInteger, String, ByteString, Symbol} -#[derive(Debug, PartialOrd, Ord, PartialEq, Eq)] pub struct Binding {pub name: std::string::String, pub pattern: std::boxed::Box} +#[derive(Debug, PartialOrd, Ord, PartialEq, Eq)] +pub struct Binding {pub name: std::string::String, pub pattern: std::boxed::Box} -#[derive(Debug, PartialOrd, Ord, PartialEq, Eq)] pub struct Bundle {pub modules: std::boxed::Box} +#[derive(Debug, PartialOrd, Ord, PartialEq, Eq)] +pub struct Bundle {pub modules: std::boxed::Box} -#[derive(Debug, PartialOrd, Ord, PartialEq, Eq)] pub enum CompoundPattern { +#[derive(Debug, PartialOrd, Ord, PartialEq, Eq)] +pub enum CompoundPattern { Rec {label: std::boxed::Box, fields: std::boxed::Box}, Tuple {patterns: std::vec::Vec}, TuplePrefix { @@ -52,7 +56,8 @@ lazy_static! { Dict {entries: std::boxed::Box} } -#[derive(Debug, PartialOrd, Ord, PartialEq, Eq)] pub enum Definition { +#[derive(Debug, PartialOrd, Ord, PartialEq, Eq)] +pub enum Definition { Or { pattern_0: std::boxed::Box, pattern_1: std::boxed::Box, @@ -66,36 +71,48 @@ lazy_static! { Pattern(std::boxed::Box) } -#[derive(Debug, PartialOrd, Ord, PartialEq, Eq)] pub struct Definitions(preserves::value::Map); +#[derive(Debug, PartialOrd, Ord, PartialEq, Eq)] +pub struct Definitions(pub preserves::value::Map); -#[derive(Debug, PartialOrd, Ord, PartialEq, Eq)] pub struct DictionaryEntries(preserves::value::Map); +#[derive(Debug, PartialOrd, Ord, PartialEq, Eq)] +pub struct DictionaryEntries(pub preserves::value::Map); -#[derive(Debug, PartialOrd, Ord, PartialEq, Eq)] pub enum EmbeddedTypeName {Ref(std::boxed::Box), False} +#[derive(Debug, PartialOrd, Ord, PartialEq, Eq)] +pub enum EmbeddedTypeName {Ref(std::boxed::Box), False} -#[derive(Debug, PartialOrd, Ord, PartialEq, Eq)] pub struct ModulePath(std::vec::Vec); +#[derive(Debug, PartialOrd, Ord, PartialEq, Eq)] +pub struct ModulePath(pub std::vec::Vec); -#[derive(Debug, PartialOrd, Ord, PartialEq, Eq)] pub struct Modules(preserves::value::Map); +#[derive(Debug, PartialOrd, Ord, PartialEq, Eq)] +pub struct Modules(pub preserves::value::Map); -#[derive(Debug, PartialOrd, Ord, PartialEq, Eq)] pub struct NamedAlternative {pub variant_label: std::string::String, pub pattern: std::boxed::Box} +#[derive(Debug, PartialOrd, Ord, PartialEq, Eq)] +pub struct NamedAlternative {pub variant_label: std::string::String, pub pattern: std::boxed::Box} -#[derive(Debug, PartialOrd, Ord, PartialEq, Eq)] pub enum NamedPattern {Named(std::boxed::Box), Anonymous(std::boxed::Box)} +#[derive(Debug, PartialOrd, Ord, PartialEq, Eq)] +pub enum NamedPattern {Named(std::boxed::Box), Anonymous(std::boxed::Box)} -#[derive(Debug, PartialOrd, Ord, PartialEq, Eq)] pub enum NamedSimplePattern {Named(std::boxed::Box), Anonymous(std::boxed::Box)} +#[derive(Debug, PartialOrd, Ord, PartialEq, Eq)] +pub enum NamedSimplePattern {Named(std::boxed::Box), Anonymous(std::boxed::Box)} -#[derive(Debug, PartialOrd, Ord, PartialEq, Eq)] pub enum Pattern { +#[derive(Debug, PartialOrd, Ord, PartialEq, Eq)] +pub enum Pattern { SimplePattern(std::boxed::Box), CompoundPattern(std::boxed::Box) } -#[derive(Debug, PartialOrd, Ord, PartialEq, Eq)] pub struct Ref {pub module: std::boxed::Box, pub name: std::string::String} +#[derive(Debug, PartialOrd, Ord, PartialEq, Eq)] +pub struct Ref {pub module: std::boxed::Box, pub name: std::string::String} -#[derive(Debug, PartialOrd, Ord, PartialEq, Eq)] pub struct Schema { +#[derive(Debug, PartialOrd, Ord, PartialEq, Eq)] +pub struct Schema { pub definitions: std::boxed::Box, pub embedded_type: std::boxed::Box, pub version: std::boxed::Box } -#[derive(Debug, PartialOrd, Ord, PartialEq, Eq)] pub enum SimplePattern { +#[derive(Debug, PartialOrd, Ord, PartialEq, Eq)] +pub enum SimplePattern { Any, Atom {atom_kind: std::boxed::Box}, Embedded {interface: std::boxed::Box}, @@ -106,7 +123,8 @@ lazy_static! { Ref(std::boxed::Box) } -#[derive(Debug, PartialOrd, Ord, PartialEq, Eq)] pub struct Version; +#[derive(Debug, PartialOrd, Ord, PartialEq, Eq)] +pub struct Version; fn _parse_atom_kind_boolean(value: &preserves::value::IOValue) -> std::result::Result {if value != &*LIT0 { return Err(()); } let _tmp0 = (); Ok(AtomKind::Boolean)}