forked from syndicate-lang/preserves
Surprisingly, associated types might simplify drastically!
This commit is contained in:
parent
6348524542
commit
8127033407
|
@ -97,7 +97,7 @@ pub fn gen_definition_reader(m: &mut ModuleContext, n: &str, d: &Definition) {
|
|||
item(seq![
|
||||
"fn ", fname.clone(), anglebrackets![
|
||||
"'de",
|
||||
"R: _support::Reader<'de, _Ptr, _Any>"],
|
||||
"R: _support::Reader<'de, _Any>"],
|
||||
"(r: &mut R) -> ",
|
||||
"std::result::Result<", names::render_constructor(n), ", _support::ParseError> ",
|
||||
block(body)])
|
||||
|
@ -132,8 +132,8 @@ pub fn gen_definition_reader(m: &mut ModuleContext, n: &str, d: &Definition) {
|
|||
}
|
||||
|
||||
item(seq![
|
||||
"impl", anglebrackets!["'de", "R: _support::Reader<'de, _Ptr, _Any>"], " ",
|
||||
"_support::Deserialize", anglebrackets!["'de", "_Ptr", "_Any", "R"], " ",
|
||||
"impl", anglebrackets!["'de", "R: _support::Reader<'de, _Any>"], " ",
|
||||
"_support::Deserialize", anglebrackets!["'de", "_Any", "R"], " ",
|
||||
"for ", names::render_constructor(n), " ", block![
|
||||
seq!["fn deserialize(r: &mut R) -> ",
|
||||
"std::result::Result<Self, _support::ParseError> ",
|
||||
|
|
|
@ -174,7 +174,7 @@ pub struct Version;
|
|||
|
||||
impl preserves::value::Domain for Version {}
|
||||
|
||||
fn read_atom_kind_boolean<'de, R: _support::Reader<'de, _Ptr, _Any>>(r: &mut R) -> std::result::Result<AtomKind, _support::ParseError> {
|
||||
fn read_atom_kind_boolean<'de, R: _support::Reader<'de, _Any>>(r: &mut R) -> std::result::Result<AtomKind, _support::ParseError> {
|
||||
match r.next_token(true)? {
|
||||
preserves::value::Token::Atom(v) => match v.value() {
|
||||
preserves::value::Value::Symbol(w) if w == "Boolean" => {}
|
||||
|
@ -186,7 +186,7 @@ fn read_atom_kind_boolean<'de, R: _support::Reader<'de, _Ptr, _Any>>(r: &mut R)
|
|||
Ok(AtomKind::Boolean)
|
||||
}
|
||||
|
||||
fn read_atom_kind_float<'de, R: _support::Reader<'de, _Ptr, _Any>>(r: &mut R) -> std::result::Result<AtomKind, _support::ParseError> {
|
||||
fn read_atom_kind_float<'de, R: _support::Reader<'de, _Any>>(r: &mut R) -> std::result::Result<AtomKind, _support::ParseError> {
|
||||
match r.next_token(true)? {
|
||||
preserves::value::Token::Atom(v) => match v.value() {
|
||||
preserves::value::Value::Symbol(w) if w == "Float" => {}
|
||||
|
@ -198,7 +198,7 @@ fn read_atom_kind_float<'de, R: _support::Reader<'de, _Ptr, _Any>>(r: &mut R) ->
|
|||
Ok(AtomKind::Float)
|
||||
}
|
||||
|
||||
fn read_atom_kind_double<'de, R: _support::Reader<'de, _Ptr, _Any>>(r: &mut R) -> std::result::Result<AtomKind, _support::ParseError> {
|
||||
fn read_atom_kind_double<'de, R: _support::Reader<'de, _Any>>(r: &mut R) -> std::result::Result<AtomKind, _support::ParseError> {
|
||||
match r.next_token(true)? {
|
||||
preserves::value::Token::Atom(v) => match v.value() {
|
||||
preserves::value::Value::Symbol(w) if w == "Double" => {}
|
||||
|
@ -210,7 +210,7 @@ fn read_atom_kind_double<'de, R: _support::Reader<'de, _Ptr, _Any>>(r: &mut R) -
|
|||
Ok(AtomKind::Double)
|
||||
}
|
||||
|
||||
fn read_atom_kind_signed_integer<'de, R: _support::Reader<'de, _Ptr, _Any>>(r: &mut R) -> std::result::Result<AtomKind, _support::ParseError> {
|
||||
fn read_atom_kind_signed_integer<'de, R: _support::Reader<'de, _Any>>(r: &mut R) -> std::result::Result<AtomKind, _support::ParseError> {
|
||||
match r.next_token(true)? {
|
||||
preserves::value::Token::Atom(v) => match v.value() {
|
||||
preserves::value::Value::Symbol(w) if w == "SignedInteger" => {}
|
||||
|
@ -222,7 +222,7 @@ fn read_atom_kind_signed_integer<'de, R: _support::Reader<'de, _Ptr, _Any>>(r: &
|
|||
Ok(AtomKind::SignedInteger)
|
||||
}
|
||||
|
||||
fn read_atom_kind_string<'de, R: _support::Reader<'de, _Ptr, _Any>>(r: &mut R) -> std::result::Result<AtomKind, _support::ParseError> {
|
||||
fn read_atom_kind_string<'de, R: _support::Reader<'de, _Any>>(r: &mut R) -> std::result::Result<AtomKind, _support::ParseError> {
|
||||
match r.next_token(true)? {
|
||||
preserves::value::Token::Atom(v) => match v.value() {
|
||||
preserves::value::Value::Symbol(w) if w == "String" => {}
|
||||
|
@ -234,7 +234,7 @@ fn read_atom_kind_string<'de, R: _support::Reader<'de, _Ptr, _Any>>(r: &mut R) -
|
|||
Ok(AtomKind::String)
|
||||
}
|
||||
|
||||
fn read_atom_kind_byte_string<'de, R: _support::Reader<'de, _Ptr, _Any>>(r: &mut R) -> std::result::Result<AtomKind, _support::ParseError> {
|
||||
fn read_atom_kind_byte_string<'de, R: _support::Reader<'de, _Any>>(r: &mut R) -> std::result::Result<AtomKind, _support::ParseError> {
|
||||
match r.next_token(true)? {
|
||||
preserves::value::Token::Atom(v) => match v.value() {
|
||||
preserves::value::Value::Symbol(w) if w == "ByteString" => {}
|
||||
|
@ -246,7 +246,7 @@ fn read_atom_kind_byte_string<'de, R: _support::Reader<'de, _Ptr, _Any>>(r: &mut
|
|||
Ok(AtomKind::ByteString)
|
||||
}
|
||||
|
||||
fn read_atom_kind_symbol<'de, R: _support::Reader<'de, _Ptr, _Any>>(r: &mut R) -> std::result::Result<AtomKind, _support::ParseError> {
|
||||
fn read_atom_kind_symbol<'de, R: _support::Reader<'de, _Any>>(r: &mut R) -> std::result::Result<AtomKind, _support::ParseError> {
|
||||
match r.next_token(true)? {
|
||||
preserves::value::Token::Atom(v) => match v.value() {
|
||||
preserves::value::Value::Symbol(w) if w == "Symbol" => {}
|
||||
|
@ -258,7 +258,7 @@ fn read_atom_kind_symbol<'de, R: _support::Reader<'de, _Ptr, _Any>>(r: &mut R) -
|
|||
Ok(AtomKind::Symbol)
|
||||
}
|
||||
|
||||
impl<'de, R: _support::Reader<'de, _Ptr, _Any>> _support::Deserialize<'de, _Ptr, _Any, R> for AtomKind {
|
||||
impl<'de, R: _support::Reader<'de, _Any>> _support::Deserialize<'de, _Any, R> for AtomKind {
|
||||
fn deserialize(r: &mut R) -> std::result::Result<Self, _support::ParseError> {
|
||||
let _mark = r.mark()?;
|
||||
match read_atom_kind_boolean(r) { Err(e) if e.is_conformance_error() => r.restore(&_mark)?, result => return result }
|
||||
|
@ -342,7 +342,7 @@ impl std::convert::From<&AtomKind> for _Any {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'de, R: _support::Reader<'de, _Ptr, _Any>> _support::Deserialize<'de, _Ptr, _Any, R> for Binding {
|
||||
impl<'de, R: _support::Reader<'de, _Any>> _support::Deserialize<'de, _Any, R> for Binding {
|
||||
fn deserialize(r: &mut R) -> std::result::Result<Self, _support::ParseError> {
|
||||
r.open_record(None)?;
|
||||
let mut _tmp0 = _support::B::Type::default();
|
||||
|
@ -392,7 +392,7 @@ impl std::convert::From<&Binding> for _Any {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'de, R: _support::Reader<'de, _Ptr, _Any>> _support::Deserialize<'de, _Ptr, _Any, R> for Bundle {
|
||||
impl<'de, R: _support::Reader<'de, _Any>> _support::Deserialize<'de, _Any, R> for Bundle {
|
||||
fn deserialize(r: &mut R) -> std::result::Result<Self, _support::ParseError> {
|
||||
r.open_record(None)?;
|
||||
let mut _tmp0 = _support::B::Type::default();
|
||||
|
@ -437,7 +437,7 @@ impl std::convert::From<&Bundle> for _Any {
|
|||
}
|
||||
}
|
||||
|
||||
fn read_compound_pattern_rec<'de, R: _support::Reader<'de, _Ptr, _Any>>(r: &mut R) -> std::result::Result<CompoundPattern, _support::ParseError> {
|
||||
fn read_compound_pattern_rec<'de, R: _support::Reader<'de, _Any>>(r: &mut R) -> std::result::Result<CompoundPattern, _support::ParseError> {
|
||||
r.open_record(None)?;
|
||||
let mut _tmp0 = _support::B::Type::default();
|
||||
_tmp0.shift(Some(_support::B::Item::RecordLabel));
|
||||
|
@ -460,7 +460,7 @@ fn read_compound_pattern_rec<'de, R: _support::Reader<'de, _Ptr, _Any>>(r: &mut
|
|||
Ok(CompoundPattern::Rec {label: std::boxed::Box::new(_tmp2), fields: std::boxed::Box::new(_tmp3)})
|
||||
}
|
||||
|
||||
fn read_compound_pattern_tuple<'de, R: _support::Reader<'de, _Ptr, _Any>>(r: &mut R) -> std::result::Result<CompoundPattern, _support::ParseError> {
|
||||
fn read_compound_pattern_tuple<'de, R: _support::Reader<'de, _Any>>(r: &mut R) -> std::result::Result<CompoundPattern, _support::ParseError> {
|
||||
r.open_record(None)?;
|
||||
let mut _tmp0 = _support::B::Type::default();
|
||||
_tmp0.shift(Some(_support::B::Item::RecordLabel));
|
||||
|
@ -489,7 +489,7 @@ fn read_compound_pattern_tuple<'de, R: _support::Reader<'de, _Ptr, _Any>>(r: &mu
|
|||
Ok(CompoundPattern::Tuple {patterns: _tmp2})
|
||||
}
|
||||
|
||||
fn read_compound_pattern_tuple_prefix<'de, R: _support::Reader<'de, _Ptr, _Any>>(r: &mut R) -> std::result::Result<CompoundPattern, _support::ParseError> {
|
||||
fn read_compound_pattern_tuple_prefix<'de, R: _support::Reader<'de, _Any>>(r: &mut R) -> std::result::Result<CompoundPattern, _support::ParseError> {
|
||||
r.open_record(None)?;
|
||||
let mut _tmp0 = _support::B::Type::default();
|
||||
_tmp0.shift(Some(_support::B::Item::RecordLabel));
|
||||
|
@ -521,7 +521,7 @@ fn read_compound_pattern_tuple_prefix<'de, R: _support::Reader<'de, _Ptr, _Any>>
|
|||
Ok(CompoundPattern::TuplePrefix {fixed: _tmp2, variable: std::boxed::Box::new(_tmp6)})
|
||||
}
|
||||
|
||||
fn read_compound_pattern_dict<'de, R: _support::Reader<'de, _Ptr, _Any>>(r: &mut R) -> std::result::Result<CompoundPattern, _support::ParseError> {
|
||||
fn read_compound_pattern_dict<'de, R: _support::Reader<'de, _Any>>(r: &mut R) -> std::result::Result<CompoundPattern, _support::ParseError> {
|
||||
r.open_record(None)?;
|
||||
let mut _tmp0 = _support::B::Type::default();
|
||||
_tmp0.shift(Some(_support::B::Item::RecordLabel));
|
||||
|
@ -541,7 +541,7 @@ fn read_compound_pattern_dict<'de, R: _support::Reader<'de, _Ptr, _Any>>(r: &mut
|
|||
Ok(CompoundPattern::Dict {entries: std::boxed::Box::new(_tmp2)})
|
||||
}
|
||||
|
||||
impl<'de, R: _support::Reader<'de, _Ptr, _Any>> _support::Deserialize<'de, _Ptr, _Any, R> for CompoundPattern {
|
||||
impl<'de, R: _support::Reader<'de, _Any>> _support::Deserialize<'de, _Any, R> for CompoundPattern {
|
||||
fn deserialize(r: &mut R) -> std::result::Result<Self, _support::ParseError> {
|
||||
let _mark = r.mark()?;
|
||||
match read_compound_pattern_rec(r) { Err(e) if e.is_conformance_error() => r.restore(&_mark)?, result => return result }
|
||||
|
@ -646,7 +646,7 @@ impl std::convert::From<&CompoundPattern> for _Any {
|
|||
}
|
||||
}
|
||||
|
||||
fn read_definition_or<'de, R: _support::Reader<'de, _Ptr, _Any>>(r: &mut R) -> std::result::Result<Definition, _support::ParseError> {
|
||||
fn read_definition_or<'de, R: _support::Reader<'de, _Any>>(r: &mut R) -> std::result::Result<Definition, _support::ParseError> {
|
||||
r.open_record(None)?;
|
||||
let mut _tmp0 = _support::B::Type::default();
|
||||
_tmp0.shift(Some(_support::B::Item::RecordLabel));
|
||||
|
@ -685,7 +685,7 @@ fn read_definition_or<'de, R: _support::Reader<'de, _Ptr, _Any>>(r: &mut R) -> s
|
|||
})
|
||||
}
|
||||
|
||||
fn read_definition_and<'de, R: _support::Reader<'de, _Ptr, _Any>>(r: &mut R) -> std::result::Result<Definition, _support::ParseError> {
|
||||
fn read_definition_and<'de, R: _support::Reader<'de, _Any>>(r: &mut R) -> std::result::Result<Definition, _support::ParseError> {
|
||||
r.open_record(None)?;
|
||||
let mut _tmp0 = _support::B::Type::default();
|
||||
_tmp0.shift(Some(_support::B::Item::RecordLabel));
|
||||
|
@ -724,12 +724,12 @@ fn read_definition_and<'de, R: _support::Reader<'de, _Ptr, _Any>>(r: &mut R) ->
|
|||
})
|
||||
}
|
||||
|
||||
fn read_definition_pattern<'de, R: _support::Reader<'de, _Ptr, _Any>>(r: &mut R) -> std::result::Result<Definition, _support::ParseError> {
|
||||
fn read_definition_pattern<'de, R: _support::Reader<'de, _Any>>(r: &mut R) -> std::result::Result<Definition, _support::ParseError> {
|
||||
let _tmp0 = Pattern::deserialize(r)?;
|
||||
Ok(Definition::Pattern(std::boxed::Box::new(_tmp0)))
|
||||
}
|
||||
|
||||
impl<'de, R: _support::Reader<'de, _Ptr, _Any>> _support::Deserialize<'de, _Ptr, _Any, R> for Definition {
|
||||
impl<'de, R: _support::Reader<'de, _Any>> _support::Deserialize<'de, _Any, R> for Definition {
|
||||
fn deserialize(r: &mut R) -> std::result::Result<Self, _support::ParseError> {
|
||||
let _mark = r.mark()?;
|
||||
match read_definition_or(r) { Err(e) if e.is_conformance_error() => r.restore(&_mark)?, result => return result }
|
||||
|
@ -824,7 +824,7 @@ impl std::convert::From<&Definition> for _Any {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'de, R: _support::Reader<'de, _Ptr, _Any>> _support::Deserialize<'de, _Ptr, _Any, R> for Definitions {
|
||||
impl<'de, R: _support::Reader<'de, _Any>> _support::Deserialize<'de, _Any, R> for Definitions {
|
||||
fn deserialize(r: &mut R) -> std::result::Result<Self, _support::ParseError> {
|
||||
r.open_dictionary()?;
|
||||
let mut _tmp2 = _support::B::Type::default();
|
||||
|
@ -863,7 +863,7 @@ impl std::convert::From<&Definitions> for _Any {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'de, R: _support::Reader<'de, _Ptr, _Any>> _support::Deserialize<'de, _Ptr, _Any, R> for DictionaryEntries {
|
||||
impl<'de, R: _support::Reader<'de, _Any>> _support::Deserialize<'de, _Any, R> for DictionaryEntries {
|
||||
fn deserialize(r: &mut R) -> std::result::Result<Self, _support::ParseError> {
|
||||
r.open_dictionary()?;
|
||||
let mut _tmp2 = _support::B::Type::default();
|
||||
|
@ -902,12 +902,12 @@ impl std::convert::From<&DictionaryEntries> for _Any {
|
|||
}
|
||||
}
|
||||
|
||||
fn read_embedded_type_name_ref<'de, R: _support::Reader<'de, _Ptr, _Any>>(r: &mut R) -> std::result::Result<EmbeddedTypeName, _support::ParseError> {
|
||||
fn read_embedded_type_name_ref<'de, R: _support::Reader<'de, _Any>>(r: &mut R) -> std::result::Result<EmbeddedTypeName, _support::ParseError> {
|
||||
let _tmp0 = Ref::deserialize(r)?;
|
||||
Ok(EmbeddedTypeName::Ref(std::boxed::Box::new(_tmp0)))
|
||||
}
|
||||
|
||||
fn read_embedded_type_name_false<'de, R: _support::Reader<'de, _Ptr, _Any>>(r: &mut R) -> std::result::Result<EmbeddedTypeName, _support::ParseError> {
|
||||
fn read_embedded_type_name_false<'de, R: _support::Reader<'de, _Any>>(r: &mut R) -> std::result::Result<EmbeddedTypeName, _support::ParseError> {
|
||||
match r.next_token(true)? {
|
||||
preserves::value::Token::Atom(v) => match v.value() {
|
||||
preserves::value::Value::Boolean(w) if !*w => {}
|
||||
|
@ -919,7 +919,7 @@ fn read_embedded_type_name_false<'de, R: _support::Reader<'de, _Ptr, _Any>>(r: &
|
|||
Ok(EmbeddedTypeName::False)
|
||||
}
|
||||
|
||||
impl<'de, R: _support::Reader<'de, _Ptr, _Any>> _support::Deserialize<'de, _Ptr, _Any, R> for EmbeddedTypeName {
|
||||
impl<'de, R: _support::Reader<'de, _Any>> _support::Deserialize<'de, _Any, R> for EmbeddedTypeName {
|
||||
fn deserialize(r: &mut R) -> std::result::Result<Self, _support::ParseError> {
|
||||
let _mark = r.mark()?;
|
||||
match read_embedded_type_name_ref(r) { Err(e) if e.is_conformance_error() => r.restore(&_mark)?, result => return result }
|
||||
|
@ -957,7 +957,7 @@ impl std::convert::From<&EmbeddedTypeName> for _Any {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'de, R: _support::Reader<'de, _Ptr, _Any>> _support::Deserialize<'de, _Ptr, _Any, R> for ModulePath {
|
||||
impl<'de, R: _support::Reader<'de, _Any>> _support::Deserialize<'de, _Any, R> for ModulePath {
|
||||
fn deserialize(r: &mut R) -> std::result::Result<Self, _support::ParseError> {
|
||||
r.open_sequence()?;
|
||||
let mut _tmp2 = _support::B::Type::default();
|
||||
|
@ -994,7 +994,7 @@ impl std::convert::From<&ModulePath> for _Any {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'de, R: _support::Reader<'de, _Ptr, _Any>> _support::Deserialize<'de, _Ptr, _Any, R> for Modules {
|
||||
impl<'de, R: _support::Reader<'de, _Any>> _support::Deserialize<'de, _Any, R> for Modules {
|
||||
fn deserialize(r: &mut R) -> std::result::Result<Self, _support::ParseError> {
|
||||
r.open_dictionary()?;
|
||||
let mut _tmp2 = _support::B::Type::default();
|
||||
|
@ -1033,7 +1033,7 @@ impl std::convert::From<&Modules> for _Any {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'de, R: _support::Reader<'de, _Ptr, _Any>> _support::Deserialize<'de, _Ptr, _Any, R> for NamedAlternative {
|
||||
impl<'de, R: _support::Reader<'de, _Any>> _support::Deserialize<'de, _Any, R> for NamedAlternative {
|
||||
fn deserialize(r: &mut R) -> std::result::Result<Self, _support::ParseError> {
|
||||
r.open_sequence()?;
|
||||
let mut _tmp0 = _support::B::Type::default();
|
||||
|
@ -1071,17 +1071,17 @@ impl std::convert::From<&NamedAlternative> for _Any {
|
|||
}
|
||||
}
|
||||
|
||||
fn read_named_pattern_named<'de, R: _support::Reader<'de, _Ptr, _Any>>(r: &mut R) -> std::result::Result<NamedPattern, _support::ParseError> {
|
||||
fn read_named_pattern_named<'de, R: _support::Reader<'de, _Any>>(r: &mut R) -> std::result::Result<NamedPattern, _support::ParseError> {
|
||||
let _tmp0 = Binding::deserialize(r)?;
|
||||
Ok(NamedPattern::Named(std::boxed::Box::new(_tmp0)))
|
||||
}
|
||||
|
||||
fn read_named_pattern_anonymous<'de, R: _support::Reader<'de, _Ptr, _Any>>(r: &mut R) -> std::result::Result<NamedPattern, _support::ParseError> {
|
||||
fn read_named_pattern_anonymous<'de, R: _support::Reader<'de, _Any>>(r: &mut R) -> std::result::Result<NamedPattern, _support::ParseError> {
|
||||
let _tmp0 = Pattern::deserialize(r)?;
|
||||
Ok(NamedPattern::Anonymous(std::boxed::Box::new(_tmp0)))
|
||||
}
|
||||
|
||||
impl<'de, R: _support::Reader<'de, _Ptr, _Any>> _support::Deserialize<'de, _Ptr, _Any, R> for NamedPattern {
|
||||
impl<'de, R: _support::Reader<'de, _Any>> _support::Deserialize<'de, _Any, R> for NamedPattern {
|
||||
fn deserialize(r: &mut R) -> std::result::Result<Self, _support::ParseError> {
|
||||
let _mark = r.mark()?;
|
||||
match read_named_pattern_named(r) { Err(e) if e.is_conformance_error() => r.restore(&_mark)?, result => return result }
|
||||
|
@ -1118,17 +1118,17 @@ impl std::convert::From<&NamedPattern> for _Any {
|
|||
}
|
||||
}
|
||||
|
||||
fn read_named_simple_pattern_named<'de, R: _support::Reader<'de, _Ptr, _Any>>(r: &mut R) -> std::result::Result<NamedSimplePattern, _support::ParseError> {
|
||||
fn read_named_simple_pattern_named<'de, R: _support::Reader<'de, _Any>>(r: &mut R) -> std::result::Result<NamedSimplePattern, _support::ParseError> {
|
||||
let _tmp0 = Binding::deserialize(r)?;
|
||||
Ok(NamedSimplePattern::Named(std::boxed::Box::new(_tmp0)))
|
||||
}
|
||||
|
||||
fn read_named_simple_pattern_anonymous<'de, R: _support::Reader<'de, _Ptr, _Any>>(r: &mut R) -> std::result::Result<NamedSimplePattern, _support::ParseError> {
|
||||
fn read_named_simple_pattern_anonymous<'de, R: _support::Reader<'de, _Any>>(r: &mut R) -> std::result::Result<NamedSimplePattern, _support::ParseError> {
|
||||
let _tmp0 = SimplePattern::deserialize(r)?;
|
||||
Ok(NamedSimplePattern::Anonymous(std::boxed::Box::new(_tmp0)))
|
||||
}
|
||||
|
||||
impl<'de, R: _support::Reader<'de, _Ptr, _Any>> _support::Deserialize<'de, _Ptr, _Any, R> for NamedSimplePattern {
|
||||
impl<'de, R: _support::Reader<'de, _Any>> _support::Deserialize<'de, _Any, R> for NamedSimplePattern {
|
||||
fn deserialize(r: &mut R) -> std::result::Result<Self, _support::ParseError> {
|
||||
let _mark = r.mark()?;
|
||||
match read_named_simple_pattern_named(r) { Err(e) if e.is_conformance_error() => r.restore(&_mark)?, result => return result }
|
||||
|
@ -1165,17 +1165,17 @@ impl std::convert::From<&NamedSimplePattern> for _Any {
|
|||
}
|
||||
}
|
||||
|
||||
fn read_pattern_simple_pattern<'de, R: _support::Reader<'de, _Ptr, _Any>>(r: &mut R) -> std::result::Result<Pattern, _support::ParseError> {
|
||||
fn read_pattern_simple_pattern<'de, R: _support::Reader<'de, _Any>>(r: &mut R) -> std::result::Result<Pattern, _support::ParseError> {
|
||||
let _tmp0 = SimplePattern::deserialize(r)?;
|
||||
Ok(Pattern::SimplePattern(std::boxed::Box::new(_tmp0)))
|
||||
}
|
||||
|
||||
fn read_pattern_compound_pattern<'de, R: _support::Reader<'de, _Ptr, _Any>>(r: &mut R) -> std::result::Result<Pattern, _support::ParseError> {
|
||||
fn read_pattern_compound_pattern<'de, R: _support::Reader<'de, _Any>>(r: &mut R) -> std::result::Result<Pattern, _support::ParseError> {
|
||||
let _tmp0 = CompoundPattern::deserialize(r)?;
|
||||
Ok(Pattern::CompoundPattern(std::boxed::Box::new(_tmp0)))
|
||||
}
|
||||
|
||||
impl<'de, R: _support::Reader<'de, _Ptr, _Any>> _support::Deserialize<'de, _Ptr, _Any, R> for Pattern {
|
||||
impl<'de, R: _support::Reader<'de, _Any>> _support::Deserialize<'de, _Any, R> for Pattern {
|
||||
fn deserialize(r: &mut R) -> std::result::Result<Self, _support::ParseError> {
|
||||
let _mark = r.mark()?;
|
||||
match read_pattern_simple_pattern(r) { Err(e) if e.is_conformance_error() => r.restore(&_mark)?, result => return result }
|
||||
|
@ -1212,7 +1212,7 @@ impl std::convert::From<&Pattern> for _Any {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'de, R: _support::Reader<'de, _Ptr, _Any>> _support::Deserialize<'de, _Ptr, _Any, R> for Ref {
|
||||
impl<'de, R: _support::Reader<'de, _Any>> _support::Deserialize<'de, _Any, R> for Ref {
|
||||
fn deserialize(r: &mut R) -> std::result::Result<Self, _support::ParseError> {
|
||||
r.open_record(None)?;
|
||||
let mut _tmp0 = _support::B::Type::default();
|
||||
|
@ -1262,7 +1262,7 @@ impl std::convert::From<&Ref> for _Any {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'de, R: _support::Reader<'de, _Ptr, _Any>> _support::Deserialize<'de, _Ptr, _Any, R> for Schema {
|
||||
impl<'de, R: _support::Reader<'de, _Any>> _support::Deserialize<'de, _Any, R> for Schema {
|
||||
fn deserialize(r: &mut R) -> std::result::Result<Self, _support::ParseError> {
|
||||
r.open_record(None)?;
|
||||
let mut _tmp0 = _support::B::Type::default();
|
||||
|
@ -1357,7 +1357,7 @@ impl std::convert::From<&Schema> for _Any {
|
|||
}
|
||||
}
|
||||
|
||||
fn read_simple_pattern_any<'de, R: _support::Reader<'de, _Ptr, _Any>>(r: &mut R) -> std::result::Result<SimplePattern, _support::ParseError> {
|
||||
fn read_simple_pattern_any<'de, R: _support::Reader<'de, _Any>>(r: &mut R) -> std::result::Result<SimplePattern, _support::ParseError> {
|
||||
match r.next_token(true)? {
|
||||
preserves::value::Token::Atom(v) => match v.value() {
|
||||
preserves::value::Value::Symbol(w) if w == "any" => {}
|
||||
|
@ -1369,7 +1369,7 @@ fn read_simple_pattern_any<'de, R: _support::Reader<'de, _Ptr, _Any>>(r: &mut R)
|
|||
Ok(SimplePattern::Any)
|
||||
}
|
||||
|
||||
fn read_simple_pattern_atom<'de, R: _support::Reader<'de, _Ptr, _Any>>(r: &mut R) -> std::result::Result<SimplePattern, _support::ParseError> {
|
||||
fn read_simple_pattern_atom<'de, R: _support::Reader<'de, _Any>>(r: &mut R) -> std::result::Result<SimplePattern, _support::ParseError> {
|
||||
r.open_record(None)?;
|
||||
let mut _tmp0 = _support::B::Type::default();
|
||||
_tmp0.shift(Some(_support::B::Item::RecordLabel));
|
||||
|
@ -1389,7 +1389,7 @@ fn read_simple_pattern_atom<'de, R: _support::Reader<'de, _Ptr, _Any>>(r: &mut R
|
|||
Ok(SimplePattern::Atom {atom_kind: std::boxed::Box::new(_tmp2)})
|
||||
}
|
||||
|
||||
fn read_simple_pattern_embedded<'de, R: _support::Reader<'de, _Ptr, _Any>>(r: &mut R) -> std::result::Result<SimplePattern, _support::ParseError> {
|
||||
fn read_simple_pattern_embedded<'de, R: _support::Reader<'de, _Any>>(r: &mut R) -> std::result::Result<SimplePattern, _support::ParseError> {
|
||||
r.open_record(None)?;
|
||||
let mut _tmp0 = _support::B::Type::default();
|
||||
_tmp0.shift(Some(_support::B::Item::RecordLabel));
|
||||
|
@ -1409,7 +1409,7 @@ fn read_simple_pattern_embedded<'de, R: _support::Reader<'de, _Ptr, _Any>>(r: &m
|
|||
Ok(SimplePattern::Embedded {interface: std::boxed::Box::new(_tmp2)})
|
||||
}
|
||||
|
||||
fn read_simple_pattern_lit<'de, R: _support::Reader<'de, _Ptr, _Any>>(r: &mut R) -> std::result::Result<SimplePattern, _support::ParseError> {
|
||||
fn read_simple_pattern_lit<'de, R: _support::Reader<'de, _Any>>(r: &mut R) -> std::result::Result<SimplePattern, _support::ParseError> {
|
||||
r.open_record(None)?;
|
||||
let mut _tmp0 = _support::B::Type::default();
|
||||
_tmp0.shift(Some(_support::B::Item::RecordLabel));
|
||||
|
@ -1429,7 +1429,7 @@ fn read_simple_pattern_lit<'de, R: _support::Reader<'de, _Ptr, _Any>>(r: &mut R)
|
|||
Ok(SimplePattern::Lit {value: _tmp2})
|
||||
}
|
||||
|
||||
fn read_simple_pattern_seqof<'de, R: _support::Reader<'de, _Ptr, _Any>>(r: &mut R) -> std::result::Result<SimplePattern, _support::ParseError> {
|
||||
fn read_simple_pattern_seqof<'de, R: _support::Reader<'de, _Any>>(r: &mut R) -> std::result::Result<SimplePattern, _support::ParseError> {
|
||||
r.open_record(None)?;
|
||||
let mut _tmp0 = _support::B::Type::default();
|
||||
_tmp0.shift(Some(_support::B::Item::RecordLabel));
|
||||
|
@ -1449,7 +1449,7 @@ fn read_simple_pattern_seqof<'de, R: _support::Reader<'de, _Ptr, _Any>>(r: &mut
|
|||
Ok(SimplePattern::Seqof {pattern: std::boxed::Box::new(_tmp2)})
|
||||
}
|
||||
|
||||
fn read_simple_pattern_setof<'de, R: _support::Reader<'de, _Ptr, _Any>>(r: &mut R) -> std::result::Result<SimplePattern, _support::ParseError> {
|
||||
fn read_simple_pattern_setof<'de, R: _support::Reader<'de, _Any>>(r: &mut R) -> std::result::Result<SimplePattern, _support::ParseError> {
|
||||
r.open_record(None)?;
|
||||
let mut _tmp0 = _support::B::Type::default();
|
||||
_tmp0.shift(Some(_support::B::Item::RecordLabel));
|
||||
|
@ -1469,7 +1469,7 @@ fn read_simple_pattern_setof<'de, R: _support::Reader<'de, _Ptr, _Any>>(r: &mut
|
|||
Ok(SimplePattern::Setof {pattern: std::boxed::Box::new(_tmp2)})
|
||||
}
|
||||
|
||||
fn read_simple_pattern_dictof<'de, R: _support::Reader<'de, _Ptr, _Any>>(r: &mut R) -> std::result::Result<SimplePattern, _support::ParseError> {
|
||||
fn read_simple_pattern_dictof<'de, R: _support::Reader<'de, _Any>>(r: &mut R) -> std::result::Result<SimplePattern, _support::ParseError> {
|
||||
r.open_record(None)?;
|
||||
let mut _tmp0 = _support::B::Type::default();
|
||||
_tmp0.shift(Some(_support::B::Item::RecordLabel));
|
||||
|
@ -1492,12 +1492,12 @@ fn read_simple_pattern_dictof<'de, R: _support::Reader<'de, _Ptr, _Any>>(r: &mut
|
|||
Ok(SimplePattern::Dictof {key: std::boxed::Box::new(_tmp2), value: std::boxed::Box::new(_tmp3)})
|
||||
}
|
||||
|
||||
fn read_simple_pattern_ref<'de, R: _support::Reader<'de, _Ptr, _Any>>(r: &mut R) -> std::result::Result<SimplePattern, _support::ParseError> {
|
||||
fn read_simple_pattern_ref<'de, R: _support::Reader<'de, _Any>>(r: &mut R) -> std::result::Result<SimplePattern, _support::ParseError> {
|
||||
let _tmp0 = Ref::deserialize(r)?;
|
||||
Ok(SimplePattern::Ref(std::boxed::Box::new(_tmp0)))
|
||||
}
|
||||
|
||||
impl<'de, R: _support::Reader<'de, _Ptr, _Any>> _support::Deserialize<'de, _Ptr, _Any, R> for SimplePattern {
|
||||
impl<'de, R: _support::Reader<'de, _Any>> _support::Deserialize<'de, _Any, R> for SimplePattern {
|
||||
fn deserialize(r: &mut R) -> std::result::Result<Self, _support::ParseError> {
|
||||
let _mark = r.mark()?;
|
||||
match read_simple_pattern_any(r) { Err(e) if e.is_conformance_error() => r.restore(&_mark)?, result => return result }
|
||||
|
@ -1633,7 +1633,7 @@ impl std::convert::From<&SimplePattern> for _Any {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'de, R: _support::Reader<'de, _Ptr, _Any>> _support::Deserialize<'de, _Ptr, _Any, R> for Version {
|
||||
impl<'de, R: _support::Reader<'de, _Any>> _support::Deserialize<'de, _Any, R> for Version {
|
||||
fn deserialize(r: &mut R) -> std::result::Result<Self, _support::ParseError> {
|
||||
match r.next_token(true)? {
|
||||
preserves::value::Token::Atom(v) => match v.value() {
|
||||
|
|
|
@ -6,7 +6,6 @@ pub use preserves::value::boundary as B;
|
|||
|
||||
use preserves::value::ArcValue;
|
||||
use preserves::value::Domain;
|
||||
use preserves::value::Embeddable;
|
||||
use preserves::value::IOValue;
|
||||
use preserves::value::NestedValue;
|
||||
use preserves::value::NoEmbeddedDomainCodec;
|
||||
|
@ -19,14 +18,14 @@ use std::sync::Arc;
|
|||
|
||||
use thiserror::Error;
|
||||
|
||||
pub trait Deserialize<'de, D: Embeddable, N: NestedValue<D>, R: Reader<'de, D, N>>
|
||||
pub trait Deserialize<'de, N: NestedValue, R: Reader<'de, N>>
|
||||
where
|
||||
Self: Sized
|
||||
{
|
||||
fn deserialize(r: &mut R) -> Result<Self, ParseError>;
|
||||
}
|
||||
|
||||
pub fn decode_lit<D: Embeddable, N: NestedValue<D>>(bs: &[u8]) -> io::Result<N> {
|
||||
pub fn decode_lit<N: NestedValue>(bs: &[u8]) -> io::Result<N> {
|
||||
preserves::value::packed::from_bytes(bs, NoEmbeddedDomainCodec)
|
||||
}
|
||||
|
||||
|
@ -45,7 +44,7 @@ pub fn encode_embedded<D: Domain>(
|
|||
where
|
||||
for<'a> IOValue: From<&'a D>
|
||||
{
|
||||
v.copy_via::<_, _, _, std::convert::Infallible>(
|
||||
v.copy_via::<_, _, std::convert::Infallible>(
|
||||
&mut |d| Ok(Value::Embedded(IOValue::from(d)))).unwrap()
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ pub use super::error::Error;
|
|||
|
||||
pub type Result<T> = std::result::Result<T, Error>;
|
||||
|
||||
pub struct Deserializer<'de, 'r, R: Reader<'de, IOValue, IOValue>> {
|
||||
pub struct Deserializer<'de, 'r, R: Reader<'de, IOValue>> {
|
||||
pub read: &'r mut R,
|
||||
phantom: PhantomData<&'de ()>,
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ where
|
|||
from_reader(&mut PackedReader::new(&mut IOBinarySource::new(read), IOValueDomainCodec))
|
||||
}
|
||||
|
||||
pub fn from_reader<'r, 'de, R: Reader<'de, IOValue, IOValue>, T>(read: &'r mut R) ->
|
||||
pub fn from_reader<'r, 'de, R: Reader<'de, IOValue>, T>(read: &'r mut R) ->
|
||||
Result<T>
|
||||
where
|
||||
T: Deserialize<'de>
|
||||
|
@ -49,13 +49,15 @@ where
|
|||
Ok(t)
|
||||
}
|
||||
|
||||
impl<'r, 'de, R: Reader<'de, IOValue, IOValue>> Deserializer<'de, 'r, R> {
|
||||
impl<'r, 'de, R: Reader<'de, IOValue>> Deserializer<'de, 'r, R> {
|
||||
pub fn from_reader(read: &'r mut R) -> Self {
|
||||
Deserializer { read, phantom: PhantomData }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'r, 'de, 'a, R: Reader<'de, IOValue, IOValue>> serde::de::Deserializer<'de> for &'a mut Deserializer<'de, 'r, R>
|
||||
impl<'r, 'de, 'a, R: Reader<'de, IOValue>>
|
||||
serde::de::Deserializer<'de>
|
||||
for &'a mut Deserializer<'de, 'r, R>
|
||||
{
|
||||
type Error = Error;
|
||||
|
||||
|
@ -266,13 +268,13 @@ impl<'r, 'de, 'a, R: Reader<'de, IOValue, IOValue>> serde::de::Deserializer<'de>
|
|||
}
|
||||
}
|
||||
|
||||
pub struct Seq<'de, 'r, 'a, R: Reader<'de, IOValue, IOValue>> {
|
||||
pub struct Seq<'de, 'r, 'a, R: Reader<'de, IOValue>> {
|
||||
b: B::Type,
|
||||
i: B::Item,
|
||||
de: &'a mut Deserializer<'de, 'r, R>,
|
||||
}
|
||||
|
||||
impl<'de, 'r, 'a, R: Reader<'de, IOValue, IOValue>> Seq<'de, 'r, 'a, R> {
|
||||
impl<'de, 'r, 'a, R: Reader<'de, IOValue>> Seq<'de, 'r, 'a, R> {
|
||||
fn new(de: &'a mut Deserializer<'de, 'r, R>, b: B::Type, i: B::Item) -> Self {
|
||||
Seq { b, i, de }
|
||||
}
|
||||
|
@ -294,7 +296,7 @@ impl<'de, 'r, 'a, R: Reader<'de, IOValue, IOValue>> Seq<'de, 'r, 'a, R> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'de, 'r, 'a, R: Reader<'de, IOValue, IOValue>> SeqAccess<'de> for Seq<'de, 'r, 'a, R> {
|
||||
impl<'de, 'r, 'a, R: Reader<'de, IOValue>> SeqAccess<'de> for Seq<'de, 'r, 'a, R> {
|
||||
type Error = Error;
|
||||
|
||||
fn next_element_seed<T>(&mut self, seed: T) ->
|
||||
|
@ -304,7 +306,7 @@ impl<'de, 'r, 'a, R: Reader<'de, IOValue, IOValue>> SeqAccess<'de> for Seq<'de,
|
|||
}
|
||||
}
|
||||
|
||||
impl<'de, 'r, 'a, R: Reader<'de, IOValue, IOValue>> MapAccess<'de> for Seq<'de, 'r, 'a, R> {
|
||||
impl<'de, 'r, 'a, R: Reader<'de, IOValue>> MapAccess<'de> for Seq<'de, 'r, 'a, R> {
|
||||
type Error = Error;
|
||||
|
||||
fn next_key_seed<K>(&mut self, seed: K) ->
|
||||
|
@ -325,7 +327,7 @@ impl<'de, 'r, 'a, R: Reader<'de, IOValue, IOValue>> MapAccess<'de> for Seq<'de,
|
|||
}
|
||||
}
|
||||
|
||||
impl<'de, 'r, 'a, R: Reader<'de, IOValue, IOValue>> EnumAccess<'de> for &'a mut Deserializer<'de, 'r, R> {
|
||||
impl<'de, 'r, 'a, R: Reader<'de, IOValue>> EnumAccess<'de> for &'a mut Deserializer<'de, 'r, R> {
|
||||
type Error = Error;
|
||||
type Variant = Seq<'de, 'r, 'a, R>;
|
||||
|
||||
|
@ -338,7 +340,7 @@ impl<'de, 'r, 'a, R: Reader<'de, IOValue, IOValue>> EnumAccess<'de> for &'a mut
|
|||
}
|
||||
}
|
||||
|
||||
impl<'de, 'r, 'a, R: Reader<'de, IOValue, IOValue>> VariantAccess<'de> for Seq<'de, 'r, 'a, R> {
|
||||
impl<'de, 'r, 'a, R: Reader<'de, IOValue>> VariantAccess<'de> for Seq<'de, 'r, 'a, R> {
|
||||
type Error = Error;
|
||||
|
||||
fn unit_variant(mut self) -> Result<()> {
|
||||
|
|
|
@ -51,8 +51,8 @@ mod ieee754_section_5_10_total_order_tests {
|
|||
use super::dom::Dom;
|
||||
|
||||
use crate::value::{Value, PlainValue};
|
||||
fn f(val: f32) -> Value<PlainValue<Dom>, Dom> { Value::from(val) }
|
||||
fn d(val: f64) -> Value<PlainValue<Dom>, Dom> { Value::from(val) }
|
||||
fn f(val: f32) -> Value<PlainValue<Dom>> { Value::from(val) }
|
||||
fn d(val: f64) -> Value<PlainValue<Dom>> { Value::from(val) }
|
||||
|
||||
// TODO: Test cases with a few different signalling and non-signalling NaNs
|
||||
|
||||
|
@ -145,7 +145,7 @@ mod value_tests {
|
|||
use crate::value::{Value, PlainValue, repr::Record, signed_integer::SignedInteger};
|
||||
use super::dom::Dom;
|
||||
|
||||
type VV = Value<PlainValue<Dom>, Dom>;
|
||||
type VV = Value<PlainValue<Dom>>;
|
||||
|
||||
#[test] fn boolean_mut() {
|
||||
let mut b = VV::Boolean(true);
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
use super::Embeddable;
|
||||
use super::Map;
|
||||
use super::NestedValue;
|
||||
use super::Record;
|
||||
use super::Value;
|
||||
|
||||
pub fn merge_seqs<N: NestedValue<D>, D: Embeddable>(mut a: Vec<N>, mut b: Vec<N>) -> Option<Vec<N>> {
|
||||
pub fn merge_seqs<N: NestedValue>(mut a: Vec<N>, mut b: Vec<N>) -> Option<Vec<N>> {
|
||||
if a.len() > b.len() {
|
||||
std::mem::swap(&mut a, &mut b);
|
||||
}
|
||||
|
@ -17,7 +16,7 @@ pub fn merge_seqs<N: NestedValue<D>, D: Embeddable>(mut a: Vec<N>, mut b: Vec<N>
|
|||
Some(r)
|
||||
}
|
||||
|
||||
pub fn merge2<N: NestedValue<D>, D: Embeddable>(v: N, w: N) -> Option<N> {
|
||||
pub fn merge2<N: NestedValue>(v: N, w: N) -> Option<N> {
|
||||
let (mut v_anns, v_val) = v.pieces();
|
||||
let (w_anns, w_val) = w.pieces();
|
||||
v_anns.modify(|anns| anns.extend(w_anns.to_vec().into_iter()));
|
||||
|
@ -49,7 +48,7 @@ pub fn merge2<N: NestedValue<D>, D: Embeddable>(v: N, w: N) -> Option<N> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn merge<N: NestedValue<D>, D: Embeddable, I: IntoIterator<Item = N>>(vs: I) -> Option<N> {
|
||||
pub fn merge<N: NestedValue, I: IntoIterator<Item = N>>(vs: I) -> Option<N> {
|
||||
let mut vs = vs.into_iter();
|
||||
let mut v = vs.next().expect("at least one value in merge()");
|
||||
for w in vs {
|
||||
|
|
|
@ -7,9 +7,9 @@ pub use writer::PackedWriter;
|
|||
|
||||
use std::io;
|
||||
|
||||
use super::{BinarySource, DomainDecode, Embeddable, IOValue, IOValueDomainCodec, NestedValue, Reader};
|
||||
use super::{BinarySource, DomainDecode, IOValue, IOValueDomainCodec, NestedValue, Reader};
|
||||
|
||||
pub fn from_bytes<D: Embeddable, N: NestedValue<D>, Dec: DomainDecode<D>>(
|
||||
pub fn from_bytes<N: NestedValue, Dec: DomainDecode<N::D>>(
|
||||
bs: &[u8],
|
||||
decode_embedded: Dec,
|
||||
) -> io::Result<N> {
|
||||
|
@ -20,7 +20,7 @@ pub fn iovalue_from_bytes(bs: &[u8]) -> io::Result<IOValue> {
|
|||
from_bytes(bs, IOValueDomainCodec)
|
||||
}
|
||||
|
||||
pub fn annotated_from_bytes<D: Embeddable, N: NestedValue<D>, Dec: DomainDecode<D>>(
|
||||
pub fn annotated_from_bytes<N: NestedValue, Dec: DomainDecode<N::D>>(
|
||||
bs: &[u8],
|
||||
decode_embedded: Dec,
|
||||
) -> io::Result<N> {
|
||||
|
|
|
@ -13,7 +13,6 @@ use super::constants::Tag;
|
|||
use super::super::{
|
||||
CompoundClass,
|
||||
DomainDecode,
|
||||
Embeddable,
|
||||
Map,
|
||||
NestedValue,
|
||||
Record,
|
||||
|
@ -31,15 +30,15 @@ use super::super::{
|
|||
signed_integer::SignedInteger,
|
||||
};
|
||||
|
||||
pub struct PackedReader<'de, 'src, D: Embeddable, N: NestedValue<D>, Dec: DomainDecode<D>, S: BinarySource<'de>> {
|
||||
pub struct PackedReader<'de, 'src, N: NestedValue, Dec: DomainDecode<N::D>, S: BinarySource<'de>> {
|
||||
pub source: &'src mut S,
|
||||
pub decode_embedded: Dec,
|
||||
phantom: PhantomData<&'de (D, N)>,
|
||||
phantom: PhantomData<&'de N>,
|
||||
}
|
||||
|
||||
impl<'de, 'src, D: Embeddable, N: NestedValue<D>, Dec: DomainDecode<D>, S: BinarySource<'de>>
|
||||
impl<'de, 'src, N: NestedValue, Dec: DomainDecode<N::D>, S: BinarySource<'de>>
|
||||
BinarySource<'de>
|
||||
for PackedReader<'de, 'src, D, N, Dec, S>
|
||||
for PackedReader<'de, 'src, N, Dec, S>
|
||||
{
|
||||
type Mark = S::Mark;
|
||||
fn mark(&mut self) -> io::Result<Self::Mark> {
|
||||
|
@ -66,7 +65,7 @@ fn out_of_range<I: Into<BigInt>>(i: I) -> error::Error {
|
|||
error::Error::NumberOutOfRange(i.into())
|
||||
}
|
||||
|
||||
impl<'de, 'src, D: Embeddable, N: NestedValue<D>, Dec: DomainDecode<D>, S: BinarySource<'de>> PackedReader<'de, 'src, D, N, Dec, S> {
|
||||
impl<'de, 'src, N: NestedValue, Dec: DomainDecode<N::D>, S: BinarySource<'de>> PackedReader<'de, 'src, N, Dec, S> {
|
||||
pub fn new(source: &'src mut S, decode_embedded: Dec) -> Self {
|
||||
PackedReader { source, decode_embedded, phantom: PhantomData }
|
||||
}
|
||||
|
@ -258,9 +257,9 @@ impl<'de, 'src, D: Embeddable, N: NestedValue<D>, Dec: DomainDecode<D>, S: Binar
|
|||
}
|
||||
}
|
||||
|
||||
impl<'de, 'src, D: Embeddable, N: NestedValue<D>, Dec: DomainDecode<D>, S: BinarySource<'de>>
|
||||
Reader<'de, D, N>
|
||||
for PackedReader<'de, 'src, D, N, Dec, S>
|
||||
impl<'de, 'src, N: NestedValue, Dec: DomainDecode<N::D>, S: BinarySource<'de>>
|
||||
Reader<'de, N>
|
||||
for PackedReader<'de, 'src, N, Dec, S>
|
||||
{
|
||||
fn next(&mut self, read_annotations: bool) -> io::Result<Option<N>> {
|
||||
match self.peek() {
|
||||
|
@ -415,7 +414,7 @@ impl<'de, 'src, D: Embeddable, N: NestedValue<D>, Dec: DomainDecode<D>, S: Binar
|
|||
self.source.restore(mark)
|
||||
}
|
||||
|
||||
fn next_token(&mut self, read_embedded_annotations: bool) -> io::Result<Token<D, N>> {
|
||||
fn next_token(&mut self, read_embedded_annotations: bool) -> io::Result<Token<N>> {
|
||||
loop {
|
||||
return Ok(match Tag::try_from(self.peek()?)? {
|
||||
Tag::Embedded => {
|
||||
|
@ -452,7 +451,7 @@ impl<'de, 'src, D: Embeddable, N: NestedValue<D>, Dec: DomainDecode<D>, S: Binar
|
|||
}
|
||||
}
|
||||
|
||||
fn next_annotations_and_token(&mut self) -> io::Result<(Vec<N>, Token<D, N>)> {
|
||||
fn next_annotations_and_token(&mut self) -> io::Result<(Vec<N>, Token<N>)> {
|
||||
match Tag::try_from(self.peek()?)? {
|
||||
Tag::Annotation => {
|
||||
self.skip()?;
|
||||
|
|
|
@ -5,7 +5,6 @@ use std::io;
|
|||
use std::ops::DerefMut;
|
||||
use super::constants::Tag;
|
||||
use super::super::DomainEncode;
|
||||
use super::super::Embeddable;
|
||||
use super::super::IOValue;
|
||||
use super::super::IOValueDomainCodec;
|
||||
use super::super::NestedValue;
|
||||
|
@ -17,7 +16,7 @@ use super::super::writer::{Writer, CompoundWriter, varint};
|
|||
pub struct PackedWriter<W: io::Write>(Suspendable<W>);
|
||||
|
||||
impl PackedWriter<&mut Vec<u8>> {
|
||||
pub fn encode<D: Embeddable, N: NestedValue<D>, Enc: DomainEncode<D>>(
|
||||
pub fn encode<N: NestedValue, Enc: DomainEncode<N::D>>(
|
||||
enc: &mut Enc,
|
||||
v: &N,
|
||||
) -> io::Result<Vec<u8>> {
|
||||
|
|
|
@ -8,7 +8,6 @@ use super::CompoundClass;
|
|||
use super::DomainDecode;
|
||||
use super::DomainParse;
|
||||
use super::Double;
|
||||
use super::Embeddable;
|
||||
use super::Float;
|
||||
use super::IOValue;
|
||||
use super::IOValueDomainCodec;
|
||||
|
@ -19,14 +18,14 @@ use super::signed_integer::SignedInteger;
|
|||
|
||||
pub type ReaderResult<T> = std::result::Result<T, error::Error>;
|
||||
|
||||
pub enum Token<D: Embeddable, N: NestedValue<D>> {
|
||||
Embedded(D),
|
||||
pub enum Token<N: NestedValue> {
|
||||
Embedded(N::D),
|
||||
Atom(N),
|
||||
Compound(CompoundClass),
|
||||
End,
|
||||
}
|
||||
|
||||
pub trait Reader<'de, D: Embeddable, N: NestedValue<D>> {
|
||||
pub trait Reader<'de, N: NestedValue> {
|
||||
fn next(&mut self, read_annotations: bool) -> io::Result<Option<N>>;
|
||||
fn open_record(&mut self, arity: Option<usize>) -> ReaderResult<B::Type>;
|
||||
fn open_sequence_or_set(&mut self) -> ReaderResult<B::Item>;
|
||||
|
@ -45,8 +44,8 @@ pub trait Reader<'de, D: Embeddable, N: NestedValue<D>> {
|
|||
fn mark(&mut self) -> io::Result<Self::Mark>;
|
||||
fn restore(&mut self, mark: &Self::Mark) -> io::Result<()>;
|
||||
|
||||
fn next_token(&mut self, read_embedded_annotations: bool) -> io::Result<Token<D, N>>;
|
||||
fn next_annotations_and_token(&mut self) -> io::Result<(Vec<N>, Token<D, N>)>;
|
||||
fn next_token(&mut self, read_embedded_annotations: bool) -> io::Result<Token<N>>;
|
||||
fn next_annotations_and_token(&mut self) -> io::Result<(Vec<N>, Token<N>)>;
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
|
@ -131,7 +130,7 @@ pub trait Reader<'de, D: Embeddable, N: NestedValue<D>> {
|
|||
}
|
||||
}
|
||||
|
||||
fn configured(self, read_annotations: bool) -> ConfiguredReader<'de, D, N, Self>
|
||||
fn configured(self, read_annotations: bool) -> ConfiguredReader<'de, N, Self>
|
||||
where
|
||||
Self: std::marker::Sized
|
||||
{
|
||||
|
@ -159,10 +158,7 @@ pub trait Reader<'de, D: Embeddable, N: NestedValue<D>> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'r, 'de, D: Embeddable, N: NestedValue<D>, R: Reader<'de, D, N>>
|
||||
Reader<'de, D, N>
|
||||
for &'r mut R
|
||||
{
|
||||
impl<'r, 'de, N: NestedValue, R: Reader<'de, N>> Reader<'de, N> for &'r mut R {
|
||||
fn next(&mut self, read_annotations: bool) -> io::Result<Option<N>> {
|
||||
(*self).next(read_annotations)
|
||||
}
|
||||
|
@ -213,11 +209,11 @@ impl<'r, 'de, D: Embeddable, N: NestedValue<D>, R: Reader<'de, D, N>>
|
|||
(*self).restore(mark)
|
||||
}
|
||||
|
||||
fn next_token(&mut self, read_embedded_annotations: bool) -> io::Result<Token<D, N>> {
|
||||
fn next_token(&mut self, read_embedded_annotations: bool) -> io::Result<Token<N>> {
|
||||
(*self).next_token(read_embedded_annotations)
|
||||
}
|
||||
|
||||
fn next_annotations_and_token(&mut self) -> io::Result<(Vec<N>, Token<D, N>)> {
|
||||
fn next_annotations_and_token(&mut self) -> io::Result<(Vec<N>, Token<N>)> {
|
||||
(*self).next_annotations_and_token()
|
||||
}
|
||||
}
|
||||
|
@ -233,30 +229,30 @@ pub trait BinarySource<'de>: Sized {
|
|||
fn readbytes(&mut self, count: usize) -> io::Result<Cow<'de, [u8]>>;
|
||||
fn readbytes_into(&mut self, bs: &mut [u8]) -> io::Result<()>;
|
||||
|
||||
fn packed<D: Embeddable, N: NestedValue<D>, Dec: DomainDecode<D>>(
|
||||
fn packed<N: NestedValue, Dec: DomainDecode<N::D>>(
|
||||
&mut self,
|
||||
decode_embedded: Dec,
|
||||
) -> super::PackedReader<'de, '_, D, N, Dec, Self> {
|
||||
) -> super::PackedReader<'de, '_, N, Dec, Self> {
|
||||
super::PackedReader::new(self, decode_embedded)
|
||||
}
|
||||
|
||||
fn packed_iovalues(&mut self) ->
|
||||
super::PackedReader<'de, '_, IOValue, IOValue, IOValueDomainCodec, Self>
|
||||
super::PackedReader<'de, '_, IOValue, IOValueDomainCodec, Self>
|
||||
{
|
||||
self.packed(IOValueDomainCodec)
|
||||
}
|
||||
|
||||
fn text<D: Embeddable, N: NestedValue<D>, Dec: DomainParse<D>>(
|
||||
fn text<N: NestedValue, Dec: DomainParse<N::D>>(
|
||||
&mut self,
|
||||
decode_embedded: Dec,
|
||||
) -> super::TextReader<'de, '_, D, Dec, Self> {
|
||||
) -> super::TextReader<'de, '_, N::D, Dec, Self> {
|
||||
super::TextReader::new(self, decode_embedded)
|
||||
}
|
||||
|
||||
fn text_iovalues(&mut self) ->
|
||||
super::TextReader<'de, '_, IOValue, ViaCodec<IOValueDomainCodec>, Self>
|
||||
{
|
||||
self.text::<_, IOValue, _>(ViaCodec::new(IOValueDomainCodec))
|
||||
self.text::<IOValue, _>(ViaCodec::new(IOValueDomainCodec))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -379,13 +375,13 @@ impl<'de> BinarySource<'de> for BytesBinarySource<'de> {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct ConfiguredReader<'de, D: Embeddable, N: NestedValue<D>, R: Reader<'de, D, N>> {
|
||||
pub struct ConfiguredReader<'de, N: NestedValue, R: Reader<'de, N>> {
|
||||
pub reader: R,
|
||||
pub read_annotations: bool,
|
||||
phantom: PhantomData<&'de (D, N)>,
|
||||
phantom: PhantomData<&'de N>,
|
||||
}
|
||||
|
||||
impl<'de, D: Embeddable, N: NestedValue<D>, R: Reader<'de, D, N>> ConfiguredReader<'de, D, N, R> {
|
||||
impl<'de, N: NestedValue, R: Reader<'de, N>> ConfiguredReader<'de, N, R> {
|
||||
pub fn new(reader: R) -> Self {
|
||||
reader.configured(true)
|
||||
}
|
||||
|
@ -399,10 +395,7 @@ impl<'de, D: Embeddable, N: NestedValue<D>, R: Reader<'de, D, N>> ConfiguredRead
|
|||
}
|
||||
}
|
||||
|
||||
impl<'de, D: Embeddable, N: NestedValue<D>, R: Reader<'de, D, N>>
|
||||
std::iter::Iterator
|
||||
for ConfiguredReader<'de, D, N, R>
|
||||
{
|
||||
impl<'de, N: NestedValue, R: Reader<'de, N>> std::iter::Iterator for ConfiguredReader<'de, N, R> {
|
||||
type Item = io::Result<N>;
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
match self.reader.next(self.read_annotations) {
|
||||
|
|
|
@ -7,7 +7,6 @@ use std::convert::TryFrom;
|
|||
use std::convert::TryInto;
|
||||
use std::fmt::Debug;
|
||||
use std::hash::{Hash, Hasher};
|
||||
use std::marker::PhantomData;
|
||||
use std::ops::Index;
|
||||
use std::ops::IndexMut;
|
||||
use std::string::String;
|
||||
|
@ -26,12 +25,14 @@ impl<T> Embeddable for T where T: Domain + Clone {}
|
|||
|
||||
impl<D: Domain> Domain for Arc<D> {}
|
||||
|
||||
pub trait NestedValue<D: Embeddable>: Sized + Debug + Clone + Eq + Hash + Ord {
|
||||
fn new<V>(v: V) -> Self where Value<Self, D>: From<V> {
|
||||
pub trait NestedValue: Sized + Debug + Clone + Eq + Hash + Ord {
|
||||
type D: Embeddable;
|
||||
|
||||
fn new<V>(v: V) -> Self where Value<Self>: From<V> {
|
||||
Value::from(v).wrap()
|
||||
}
|
||||
|
||||
fn domain<E>(e: E) -> Self where D: From<E> {
|
||||
fn domain<E>(e: E) -> Self where Self::D: From<E> {
|
||||
Value::Embedded(e.into()).wrap()
|
||||
}
|
||||
|
||||
|
@ -43,12 +44,12 @@ pub trait NestedValue<D: Embeddable>: Sized + Debug + Clone + Eq + Hash + Ord {
|
|||
Value::bytestring(v).wrap()
|
||||
}
|
||||
|
||||
fn wrap(anns: Annotations<Self, D>, v: Value<Self, D>) -> Self;
|
||||
fn wrap(anns: Annotations<Self>, v: Value<Self>) -> Self;
|
||||
|
||||
fn annotations(&self) -> &Annotations<Self, D>;
|
||||
fn value(&self) -> &Value<Self, D>;
|
||||
fn pieces(self) -> (Annotations<Self, D>, Value<Self, D>);
|
||||
fn value_owned(self) -> Value<Self, D>;
|
||||
fn annotations(&self) -> &Annotations<Self>;
|
||||
fn value(&self) -> &Value<Self>;
|
||||
fn pieces(self) -> (Annotations<Self>, Value<Self>);
|
||||
fn value_owned(self) -> Value<Self>;
|
||||
|
||||
fn value_class(&self) -> ValueClass {
|
||||
self.value().value_class()
|
||||
|
@ -61,16 +62,16 @@ pub trait NestedValue<D: Embeddable>: Sized + Debug + Clone + Eq + Hash + Ord {
|
|||
self.value().fmt(f)
|
||||
}
|
||||
|
||||
fn copy_via<M: NestedValue<E>, E: Embeddable, F, Err>(&self, f: &mut F) -> Result<M, Err>
|
||||
fn copy_via<M: NestedValue, F, Err>(&self, f: &mut F) -> Result<M, Err>
|
||||
where
|
||||
F: FnMut(&D) -> Result<Value<M, E>, Err>
|
||||
F: FnMut(&Self::D) -> Result<Value<M>, Err>
|
||||
{
|
||||
Ok(M::wrap(self.annotations().copy_via(f)?, self.value().copy_via(f)?))
|
||||
}
|
||||
|
||||
fn foreach_embedded<F, Err>(&self, f: &mut F) -> Result<(), Err>
|
||||
where
|
||||
F: FnMut(&D) -> Result<(), Err>
|
||||
F: FnMut(&Self::D) -> Result<(), Err>
|
||||
{
|
||||
match &self.annotations().0 {
|
||||
None => (),
|
||||
|
@ -82,7 +83,7 @@ pub trait NestedValue<D: Embeddable>: Sized + Debug + Clone + Eq + Hash + Ord {
|
|||
|
||||
/// The `Value`s from the specification.
|
||||
#[derive(Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||
pub enum Value<N, D> where N: NestedValue<D>, D: Embeddable {
|
||||
pub enum Value<N: NestedValue> {
|
||||
Boolean(bool),
|
||||
Float(Float),
|
||||
Double(Double),
|
||||
|
@ -94,7 +95,7 @@ pub enum Value<N, D> where N: NestedValue<D>, D: Embeddable {
|
|||
Sequence(Vec<N>),
|
||||
Set(Set<N>),
|
||||
Dictionary(Map<N, N>),
|
||||
Embedded(D),
|
||||
Embedded(N::D),
|
||||
}
|
||||
|
||||
/// The kinds of `Value` from the specification.
|
||||
|
@ -167,7 +168,7 @@ impl<N> Record<N> {
|
|||
&mut self.0
|
||||
}
|
||||
|
||||
pub fn finish<D: Embeddable>(self) -> Value<N, D> where N: NestedValue<D> {
|
||||
pub fn finish(self) -> Value<N> where N: NestedValue {
|
||||
Value::Record(self)
|
||||
}
|
||||
}
|
||||
|
@ -256,44 +257,44 @@ impl PartialOrd for Double {
|
|||
|
||||
impl Eq for Double {}
|
||||
|
||||
impl<N: NestedValue<D>, D: Embeddable> From<bool> for Value<N, D> { fn from(v: bool) -> Self { Value::Boolean(v) } }
|
||||
impl<N: NestedValue<D>, D: Embeddable> From<&bool> for Value<N, D> { fn from(v: &bool) -> Self { Value::Boolean(*v) } }
|
||||
impl<N: NestedValue> From<bool> for Value<N> { fn from(v: bool) -> Self { Value::Boolean(v) } }
|
||||
impl<N: NestedValue> From<&bool> for Value<N> { fn from(v: &bool) -> Self { Value::Boolean(*v) } }
|
||||
|
||||
impl<N: NestedValue<D>, D: Embeddable> From<f32> for Value<N, D> { fn from(v: f32) -> Self { Value::Float(Float::from(v)) } }
|
||||
impl<N: NestedValue<D>, D: Embeddable> From<&f32> for Value<N, D> { fn from(v: &f32) -> Self { Value::Float(Float::from(*v)) } }
|
||||
impl<N: NestedValue<D>, D: Embeddable> From<&Float> for Value<N, D> { fn from(v: &Float) -> Self { Value::Float(v.clone()) } }
|
||||
impl<N: NestedValue<D>, D: Embeddable> From<f64> for Value<N, D> { fn from(v: f64) -> Self { Value::Double(Double::from(v)) } }
|
||||
impl<N: NestedValue<D>, D: Embeddable> From<&f64> for Value<N, D> { fn from(v: &f64) -> Self { Value::Double(Double::from(*v)) } }
|
||||
impl<N: NestedValue<D>, D: Embeddable> From<&Double> for Value<N, D> { fn from(v: &Double) -> Self { Value::Double(v.clone()) } }
|
||||
impl<N: NestedValue> From<f32> for Value<N> { fn from(v: f32) -> Self { Value::Float(Float::from(v)) } }
|
||||
impl<N: NestedValue> From<&f32> for Value<N> { fn from(v: &f32) -> Self { Value::Float(Float::from(*v)) } }
|
||||
impl<N: NestedValue> From<&Float> for Value<N> { fn from(v: &Float) -> Self { Value::Float(v.clone()) } }
|
||||
impl<N: NestedValue> From<f64> for Value<N> { fn from(v: f64) -> Self { Value::Double(Double::from(v)) } }
|
||||
impl<N: NestedValue> From<&f64> for Value<N> { fn from(v: &f64) -> Self { Value::Double(Double::from(*v)) } }
|
||||
impl<N: NestedValue> From<&Double> for Value<N> { fn from(v: &Double) -> Self { Value::Double(v.clone()) } }
|
||||
|
||||
impl<N: NestedValue<D>, D: Embeddable> From<u8> for Value<N, D> { fn from(v: u8) -> Self { Value::from(i128::from(v)) } }
|
||||
impl<N: NestedValue<D>, D: Embeddable> From<i8> for Value<N, D> { fn from(v: i8) -> Self { Value::from(i128::from(v)) } }
|
||||
impl<N: NestedValue<D>, D: Embeddable> From<u16> for Value<N, D> { fn from(v: u16) -> Self { Value::from(i128::from(v)) } }
|
||||
impl<N: NestedValue<D>, D: Embeddable> From<i16> for Value<N, D> { fn from(v: i16) -> Self { Value::from(i128::from(v)) } }
|
||||
impl<N: NestedValue<D>, D: Embeddable> From<u32> for Value<N, D> { fn from(v: u32) -> Self { Value::from(i128::from(v)) } }
|
||||
impl<N: NestedValue<D>, D: Embeddable> From<i32> for Value<N, D> { fn from(v: i32) -> Self { Value::from(i128::from(v)) } }
|
||||
impl<N: NestedValue<D>, D: Embeddable> From<u64> for Value<N, D> { fn from(v: u64) -> Self { Value::from(i128::from(v)) } }
|
||||
impl<N: NestedValue<D>, D: Embeddable> From<i64> for Value<N, D> { fn from(v: i64) -> Self { Value::from(i128::from(v)) } }
|
||||
impl<N: NestedValue<D>, D: Embeddable> From<usize> for Value<N, D> { fn from(v: usize) -> Self { Value::from(v as u128) } }
|
||||
impl<N: NestedValue<D>, D: Embeddable> From<isize> for Value<N, D> { fn from(v: isize) -> Self { Value::from(v as i128) } }
|
||||
impl<N: NestedValue<D>, D: Embeddable> From<u128> for Value<N, D> { fn from(v: u128) -> Self { Value::SignedInteger(SignedInteger::from(v)) } }
|
||||
impl<N: NestedValue<D>, D: Embeddable> From<i128> for Value<N, D> { fn from(v: i128) -> Self { Value::SignedInteger(SignedInteger::from(v)) } }
|
||||
impl<N: NestedValue<D>, D: Embeddable> From<&BigInt> for Value<N, D> { fn from(v: &BigInt) -> Self { Value::SignedInteger(SignedInteger::from(Cow::Borrowed(v))) } }
|
||||
impl<N: NestedValue<D>, D: Embeddable> From<BigInt> for Value<N, D> { fn from(v: BigInt) -> Self { Value::SignedInteger(SignedInteger::from(Cow::Owned(v))) } }
|
||||
impl<N: NestedValue<D>, D: Embeddable> From<&SignedInteger> for Value<N, D> { fn from(v: &SignedInteger) -> Self { Value::SignedInteger(v.clone()) } }
|
||||
impl<N: NestedValue> From<u8> for Value<N> { fn from(v: u8) -> Self { Value::from(i128::from(v)) } }
|
||||
impl<N: NestedValue> From<i8> for Value<N> { fn from(v: i8) -> Self { Value::from(i128::from(v)) } }
|
||||
impl<N: NestedValue> From<u16> for Value<N> { fn from(v: u16) -> Self { Value::from(i128::from(v)) } }
|
||||
impl<N: NestedValue> From<i16> for Value<N> { fn from(v: i16) -> Self { Value::from(i128::from(v)) } }
|
||||
impl<N: NestedValue> From<u32> for Value<N> { fn from(v: u32) -> Self { Value::from(i128::from(v)) } }
|
||||
impl<N: NestedValue> From<i32> for Value<N> { fn from(v: i32) -> Self { Value::from(i128::from(v)) } }
|
||||
impl<N: NestedValue> From<u64> for Value<N> { fn from(v: u64) -> Self { Value::from(i128::from(v)) } }
|
||||
impl<N: NestedValue> From<i64> for Value<N> { fn from(v: i64) -> Self { Value::from(i128::from(v)) } }
|
||||
impl<N: NestedValue> From<usize> for Value<N> { fn from(v: usize) -> Self { Value::from(v as u128) } }
|
||||
impl<N: NestedValue> From<isize> for Value<N> { fn from(v: isize) -> Self { Value::from(v as i128) } }
|
||||
impl<N: NestedValue> From<u128> for Value<N> { fn from(v: u128) -> Self { Value::SignedInteger(SignedInteger::from(v)) } }
|
||||
impl<N: NestedValue> From<i128> for Value<N> { fn from(v: i128) -> Self { Value::SignedInteger(SignedInteger::from(v)) } }
|
||||
impl<N: NestedValue> From<&BigInt> for Value<N> { fn from(v: &BigInt) -> Self { Value::SignedInteger(SignedInteger::from(Cow::Borrowed(v))) } }
|
||||
impl<N: NestedValue> From<BigInt> for Value<N> { fn from(v: BigInt) -> Self { Value::SignedInteger(SignedInteger::from(Cow::Owned(v))) } }
|
||||
impl<N: NestedValue> From<&SignedInteger> for Value<N> { fn from(v: &SignedInteger) -> Self { Value::SignedInteger(v.clone()) } }
|
||||
|
||||
impl<N: NestedValue<D>, D: Embeddable> From<&str> for Value<N, D> { fn from(v: &str) -> Self { Value::String(String::from(v)) } }
|
||||
impl<N: NestedValue<D>, D: Embeddable> From<String> for Value<N, D> { fn from(v: String) -> Self { Value::String(v) } }
|
||||
impl<N: NestedValue<D>, D: Embeddable> From<&String> for Value<N, D> { fn from(v: &String) -> Self { Value::String(v.to_owned()) } }
|
||||
impl<N: NestedValue> From<&str> for Value<N> { fn from(v: &str) -> Self { Value::String(String::from(v)) } }
|
||||
impl<N: NestedValue> From<String> for Value<N> { fn from(v: String) -> Self { Value::String(v) } }
|
||||
impl<N: NestedValue> From<&String> for Value<N> { fn from(v: &String) -> Self { Value::String(v.to_owned()) } }
|
||||
|
||||
impl<N: NestedValue<D>, D: Embeddable> From<&[u8]> for Value<N, D> { fn from(v: &[u8]) -> Self { Value::ByteString(Vec::from(v)) } }
|
||||
// impl<N: NestedValue<D>, D: Embeddable> From<Vec<u8>> for Value<N, D> { fn from(v: Vec<u8>) -> Self { Value::ByteString(v) } }
|
||||
impl<N: NestedValue> From<&[u8]> for Value<N> { fn from(v: &[u8]) -> Self { Value::ByteString(Vec::from(v)) } }
|
||||
// impl<N: NestedValue> From<Vec<u8>> for Value<N> { fn from(v: Vec<u8>) -> Self { Value::ByteString(v) } }
|
||||
|
||||
impl<N: NestedValue<D>, D: Embeddable> From<Vec<N>> for Value<N, D> { fn from(v: Vec<N>) -> Self { Value::Sequence(v) } }
|
||||
impl<N: NestedValue<D>, D: Embeddable> From<Set<N>> for Value<N, D> { fn from(v: Set<N>) -> Self { Value::Set(v) } }
|
||||
impl<N: NestedValue<D>, D: Embeddable> From<Map<N, N>> for Value<N, D> { fn from(v: Map<N, N>) -> Self { Value::Dictionary(v) } }
|
||||
impl<N: NestedValue> From<Vec<N>> for Value<N> { fn from(v: Vec<N>) -> Self { Value::Sequence(v) } }
|
||||
impl<N: NestedValue> From<Set<N>> for Value<N> { fn from(v: Set<N>) -> Self { Value::Set(v) } }
|
||||
impl<N: NestedValue> From<Map<N, N>> for Value<N> { fn from(v: Map<N, N>) -> Self { Value::Dictionary(v) } }
|
||||
|
||||
impl<N: NestedValue<D>, D: Embeddable> Debug for Value<N, D> {
|
||||
impl<N: NestedValue> Debug for Value<N> {
|
||||
// Not *quite* a formatter for the Preserves text syntax, since it
|
||||
// doesn't escape strings/symbols properly.
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
|
@ -339,7 +340,7 @@ impl<N: NestedValue<D>, D: Embeddable> Debug for Value<N, D> {
|
|||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
impl<N: NestedValue<D>, D: Embeddable> Value<N, D> {
|
||||
impl<N: NestedValue> Value<N> {
|
||||
pub fn wrap(self) -> N {
|
||||
N::wrap(Annotations::empty(), self)
|
||||
}
|
||||
|
@ -690,7 +691,7 @@ impl<N: NestedValue<D>, D: Embeddable> Value<N, D> {
|
|||
self.as_bytestring().ok_or_else(|| self.expected(ExpectedKind::ByteString))
|
||||
}
|
||||
|
||||
pub fn symbol(s: &str) -> Value<N, D> {
|
||||
pub fn symbol(s: &str) -> Value<N> {
|
||||
Value::Symbol(s.to_string())
|
||||
}
|
||||
|
||||
|
@ -767,11 +768,11 @@ impl<N: NestedValue<D>, D: Embeddable> Value<N, D> {
|
|||
Self::record(N::symbol(label), expected_arity)
|
||||
}
|
||||
|
||||
pub fn simple_record0(label: &str) -> Value<N, D> {
|
||||
pub fn simple_record0(label: &str) -> Value<N> {
|
||||
Self::simple_record(label, 0).finish()
|
||||
}
|
||||
|
||||
pub fn simple_record1(label: &str, field: N) -> Value<N, D> {
|
||||
pub fn simple_record1(label: &str, field: N) -> Value<N> {
|
||||
let mut r = Self::simple_record(label, 1);
|
||||
r.fields_vec_mut().push(field);
|
||||
r.finish()
|
||||
|
@ -904,7 +905,7 @@ impl<N: NestedValue<D>, D: Embeddable> Value<N, D> {
|
|||
self.as_embedded().is_some()
|
||||
}
|
||||
|
||||
pub fn as_embedded(&self) -> Option<&D> {
|
||||
pub fn as_embedded(&self) -> Option<&N::D> {
|
||||
if let Value::Embedded(d) = self {
|
||||
Some(d)
|
||||
} else {
|
||||
|
@ -912,13 +913,13 @@ impl<N: NestedValue<D>, D: Embeddable> Value<N, D> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn to_embedded(&self) -> Result<&D, Error> {
|
||||
pub fn to_embedded(&self) -> Result<&N::D, Error> {
|
||||
self.as_embedded().ok_or_else(|| self.expected(ExpectedKind::Embedded))
|
||||
}
|
||||
|
||||
pub fn copy_via<M: NestedValue<E>, E: Embeddable, F, Err>(&self, f: &mut F) -> Result<Value<M, E>, Err>
|
||||
pub fn copy_via<M: NestedValue, F, Err>(&self, f: &mut F) -> Result<Value<M>, Err>
|
||||
where
|
||||
F: FnMut(&D) -> Result<Value<M, E>, Err>
|
||||
F: FnMut(&N::D) -> Result<Value<M>, Err>
|
||||
{
|
||||
Ok(match self {
|
||||
Value::Boolean(b) => Value::Boolean(*b),
|
||||
|
@ -944,7 +945,7 @@ impl<N: NestedValue<D>, D: Embeddable> Value<N, D> {
|
|||
|
||||
pub fn foreach_embedded<F, Err>(&self, f: &mut F) -> Result<(), Err>
|
||||
where
|
||||
F: FnMut(&D) -> Result<(), Err>
|
||||
F: FnMut(&N::D) -> Result<(), Err>
|
||||
{
|
||||
match self {
|
||||
Value::Boolean(_) |
|
||||
|
@ -966,7 +967,7 @@ impl<N: NestedValue<D>, D: Embeddable> Value<N, D> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<N: NestedValue<D>, D: Embeddable> Index<usize> for Value<N, D> {
|
||||
impl<N: NestedValue> Index<usize> for Value<N> {
|
||||
type Output = N;
|
||||
|
||||
fn index(&self, i: usize) -> &Self::Output {
|
||||
|
@ -974,13 +975,13 @@ impl<N: NestedValue<D>, D: Embeddable> Index<usize> for Value<N, D> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<N: NestedValue<D>, D: Embeddable> IndexMut<usize> for Value<N, D> {
|
||||
impl<N: NestedValue> IndexMut<usize> for Value<N> {
|
||||
fn index_mut(&mut self, i: usize) -> &mut Self::Output {
|
||||
&mut self.as_sequence_mut().unwrap()[i]
|
||||
}
|
||||
}
|
||||
|
||||
impl<N: NestedValue<D>, D: Embeddable> Index<&N> for Value<N, D> {
|
||||
impl<N: NestedValue> Index<&N> for Value<N> {
|
||||
type Output = N;
|
||||
|
||||
fn index(&self, i: &N) -> &Self::Output {
|
||||
|
@ -1006,16 +1007,15 @@ impl<'de> serde::Deserialize<'de> for UnwrappedIOValue {
|
|||
//---------------------------------------------------------------------------
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Annotations<N: NestedValue<D>, D: Embeddable>(Option<Vec<N>>, PhantomData<D>);
|
||||
pub struct Annotations<N: NestedValue>(Option<Vec<N>>);
|
||||
|
||||
impl<N: NestedValue<D>, D: Embeddable> Annotations<N, D> {
|
||||
impl<N: NestedValue> Annotations<N> {
|
||||
pub fn empty() -> Self {
|
||||
Annotations(None,
|
||||
PhantomData)
|
||||
Annotations(None)
|
||||
}
|
||||
|
||||
pub fn new(anns: Option<Vec<N>>) -> Self {
|
||||
Annotations(anns, PhantomData)
|
||||
Annotations(anns)
|
||||
}
|
||||
|
||||
pub fn maybe_slice(&self) -> Option<&[N]> {
|
||||
|
@ -1043,16 +1043,15 @@ impl<N: NestedValue<D>, D: Embeddable> Annotations<N, D> {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn copy_via<M: NestedValue<E>, E: Embeddable, F, Err>(&self, f: &mut F) -> Result<Annotations<M, E>, Err>
|
||||
pub fn copy_via<M: NestedValue, F, Err>(&self, f: &mut F) -> Result<Annotations<M>, Err>
|
||||
where
|
||||
F: FnMut(&D) -> Result<Value<M, E>, Err>
|
||||
F: FnMut(&N::D) -> Result<Value<M>, Err>
|
||||
{
|
||||
Ok(match &self.0 {
|
||||
None =>
|
||||
Annotations(None, PhantomData),
|
||||
Annotations(None),
|
||||
Some(b) =>
|
||||
Annotations(Some(b.iter().map(|a| a.copy_via(f)).collect::<Result<Vec<_>, _>>()?),
|
||||
PhantomData),
|
||||
Annotations(Some(b.iter().map(|a| a.copy_via(f)).collect::<Result<Vec<_>, _>>()?)),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -1060,35 +1059,35 @@ impl<N: NestedValue<D>, D: Embeddable> Annotations<N, D> {
|
|||
/// A possibly-annotated Value, with annotations (themselves
|
||||
/// possibly-annotated) in order of appearance.
|
||||
#[derive(Clone)]
|
||||
pub struct AnnotatedValue<N: NestedValue<D>, D: Embeddable>(pub Annotations<N, D>, pub Value<N, D>);
|
||||
pub struct AnnotatedValue<N: NestedValue>(pub Annotations<N>, pub Value<N>);
|
||||
|
||||
impl<N: NestedValue<D>, D: Embeddable> AnnotatedValue<N, D> {
|
||||
fn new(anns: Annotations<N, D>, value: Value<N, D>) -> Self {
|
||||
impl<N: NestedValue> AnnotatedValue<N> {
|
||||
fn new(anns: Annotations<N>, value: Value<N>) -> Self {
|
||||
AnnotatedValue(anns, value)
|
||||
}
|
||||
}
|
||||
|
||||
impl<N: NestedValue<D>, D: Embeddable> PartialEq for AnnotatedValue<N, D> {
|
||||
impl<N: NestedValue> PartialEq for AnnotatedValue<N> {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.1.eq(&other.1)
|
||||
}
|
||||
}
|
||||
|
||||
impl<N: NestedValue<D>, D: Embeddable> Eq for AnnotatedValue<N, D> {}
|
||||
impl<N: NestedValue> Eq for AnnotatedValue<N> {}
|
||||
|
||||
impl<N: NestedValue<D>, D: Embeddable> Hash for AnnotatedValue<N, D> {
|
||||
impl<N: NestedValue> Hash for AnnotatedValue<N> {
|
||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||
self.1.hash(state);
|
||||
}
|
||||
}
|
||||
|
||||
impl<N: NestedValue<D>, D: Embeddable> PartialOrd for AnnotatedValue<N, D> {
|
||||
impl<N: NestedValue> PartialOrd for AnnotatedValue<N> {
|
||||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
||||
Some(self.cmp(other))
|
||||
}
|
||||
}
|
||||
|
||||
impl<N: NestedValue<D>, D: Embeddable> Ord for AnnotatedValue<N, D> {
|
||||
impl<N: NestedValue> Ord for AnnotatedValue<N> {
|
||||
fn cmp(&self, other: &Self) -> Ordering {
|
||||
self.1.cmp(&other.1)
|
||||
}
|
||||
|
@ -1097,37 +1096,39 @@ impl<N: NestedValue<D>, D: Embeddable> Ord for AnnotatedValue<N, D> {
|
|||
//---------------------------------------------------------------------------
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||
pub struct PlainValue<D: Embeddable>(AnnotatedValue<PlainValue<D>, D>);
|
||||
pub struct PlainValue<D: Embeddable>(AnnotatedValue<PlainValue<D>>);
|
||||
|
||||
impl<D: Embeddable> PlainValue<D> {
|
||||
pub fn annotations_mut(&mut self) -> &mut Annotations<Self, D> {
|
||||
pub fn annotations_mut(&mut self) -> &mut Annotations<Self> {
|
||||
&mut (self.0).0
|
||||
}
|
||||
|
||||
pub fn value_mut(&mut self) -> &mut Value<Self, D> {
|
||||
pub fn value_mut(&mut self) -> &mut Value<Self> {
|
||||
&mut (self.0).1
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: Embeddable> NestedValue<D> for PlainValue<D> {
|
||||
fn wrap(anns: Annotations<Self, D>, v: Value<Self, D>) -> Self {
|
||||
impl<D: Embeddable> NestedValue for PlainValue<D> {
|
||||
type D = D;
|
||||
|
||||
fn wrap(anns: Annotations<Self>, v: Value<Self>) -> Self {
|
||||
PlainValue(AnnotatedValue::new(anns, v))
|
||||
}
|
||||
|
||||
fn annotations(&self) -> &Annotations<Self, D> {
|
||||
fn annotations(&self) -> &Annotations<Self> {
|
||||
&(self.0).0
|
||||
}
|
||||
|
||||
fn value(&self) -> &Value<Self, D> {
|
||||
fn value(&self) -> &Value<Self> {
|
||||
&(self.0).1
|
||||
}
|
||||
|
||||
fn pieces(self) -> (Annotations<Self, D>, Value<Self, D>) {
|
||||
fn pieces(self) -> (Annotations<Self>, Value<Self>) {
|
||||
let AnnotatedValue(anns, v) = self.0;
|
||||
(anns, v)
|
||||
}
|
||||
|
||||
fn value_owned(self) -> Value<Self, D> {
|
||||
fn value_owned(self) -> Value<Self> {
|
||||
(self.0).1
|
||||
}
|
||||
}
|
||||
|
@ -1143,29 +1144,31 @@ impl<D: Embeddable> Debug for PlainValue<D> {
|
|||
use std::rc::Rc;
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||
pub struct RcValue<D: Embeddable>(Rc<AnnotatedValue<RcValue<D>, D>>);
|
||||
pub struct RcValue<D: Embeddable>(Rc<AnnotatedValue<RcValue<D>>>);
|
||||
|
||||
impl<D: Embeddable> NestedValue<D> for RcValue<D> {
|
||||
fn wrap(anns: Annotations<Self, D>, v: Value<Self, D>) -> Self {
|
||||
impl<D: Embeddable> NestedValue for RcValue<D> {
|
||||
type D = D;
|
||||
|
||||
fn wrap(anns: Annotations<Self>, v: Value<Self>) -> Self {
|
||||
RcValue(Rc::new(AnnotatedValue::new(anns, v)))
|
||||
}
|
||||
|
||||
fn annotations(&self) -> &Annotations<Self, D> {
|
||||
fn annotations(&self) -> &Annotations<Self> {
|
||||
&(self.0).0
|
||||
}
|
||||
|
||||
fn value(&self) -> &Value<Self, D> {
|
||||
fn value(&self) -> &Value<Self> {
|
||||
&(self.0).1
|
||||
}
|
||||
|
||||
fn pieces(self) -> (Annotations<Self, D>, Value<Self, D>) {
|
||||
fn pieces(self) -> (Annotations<Self>, Value<Self>) {
|
||||
match Rc::try_unwrap(self.0) {
|
||||
Ok(AnnotatedValue(anns, v)) => (anns, v),
|
||||
Err(r) => (r.0.clone(), r.1.clone()),
|
||||
}
|
||||
}
|
||||
|
||||
fn value_owned(self) -> Value<Self, D> {
|
||||
fn value_owned(self) -> Value<Self> {
|
||||
Rc::try_unwrap(self.0).unwrap_or_else(|_| panic!("value_owned on RcValue with refcount greater than one")).1
|
||||
}
|
||||
}
|
||||
|
@ -1179,29 +1182,31 @@ impl<D: Embeddable> Debug for RcValue<D> {
|
|||
//---------------------------------------------------------------------------
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||
pub struct ArcValue<D: Embeddable>(Arc<AnnotatedValue<ArcValue<D>, D>>);
|
||||
pub struct ArcValue<D: Embeddable>(Arc<AnnotatedValue<ArcValue<D>>>);
|
||||
|
||||
impl<D: Embeddable> NestedValue<D> for ArcValue<D> {
|
||||
fn wrap(anns: Annotations<Self, D>, v: Value<Self, D>) -> Self {
|
||||
impl<D: Embeddable> NestedValue for ArcValue<D> {
|
||||
type D = D;
|
||||
|
||||
fn wrap(anns: Annotations<Self>, v: Value<Self>) -> Self {
|
||||
ArcValue(Arc::new(AnnotatedValue::new(anns, v)))
|
||||
}
|
||||
|
||||
fn annotations(&self) -> &Annotations<Self, D> {
|
||||
fn annotations(&self) -> &Annotations<Self> {
|
||||
&(self.0).0
|
||||
}
|
||||
|
||||
fn value(&self) -> &Value<Self, D> {
|
||||
fn value(&self) -> &Value<Self> {
|
||||
&(self.0).1
|
||||
}
|
||||
|
||||
fn pieces(self) -> (Annotations<Self, D>, Value<Self, D>) {
|
||||
fn pieces(self) -> (Annotations<Self>, Value<Self>) {
|
||||
match Arc::try_unwrap(self.0) {
|
||||
Ok(AnnotatedValue(anns, v)) => (anns, v),
|
||||
Err(r) => (r.0.clone(), r.1.clone()),
|
||||
}
|
||||
}
|
||||
|
||||
fn value_owned(self) -> Value<Self, D> {
|
||||
fn value_owned(self) -> Value<Self> {
|
||||
Arc::try_unwrap(self.0).unwrap_or_else(|_| panic!("value_owned on ArcValue with refcount greater than one")).1
|
||||
}
|
||||
}
|
||||
|
@ -1215,32 +1220,34 @@ impl<D: Embeddable> Debug for ArcValue<D> {
|
|||
//---------------------------------------------------------------------------
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||
pub struct IOValue(Arc<AnnotatedValue<IOValue, IOValue>>);
|
||||
pub type UnwrappedIOValue = Value<IOValue, IOValue>;
|
||||
pub struct IOValue(Arc<AnnotatedValue<IOValue>>);
|
||||
pub type UnwrappedIOValue = Value<IOValue>;
|
||||
|
||||
impl Domain for IOValue {}
|
||||
|
||||
impl NestedValue<IOValue> for IOValue {
|
||||
fn wrap(anns: Annotations<Self, IOValue>, v: Value<Self, IOValue>) -> Self {
|
||||
impl NestedValue for IOValue {
|
||||
type D = Self;
|
||||
|
||||
fn wrap(anns: Annotations<Self>, v: Value<Self>) -> Self {
|
||||
IOValue(Arc::new(AnnotatedValue::new(anns, v)))
|
||||
}
|
||||
|
||||
fn annotations(&self) -> &Annotations<Self, IOValue> {
|
||||
fn annotations(&self) -> &Annotations<Self> {
|
||||
&(self.0).0
|
||||
}
|
||||
|
||||
fn value(&self) -> &Value<Self, IOValue> {
|
||||
fn value(&self) -> &Value<Self> {
|
||||
&(self.0).1
|
||||
}
|
||||
|
||||
fn pieces(self) -> (Annotations<Self, IOValue>, Value<Self, IOValue>) {
|
||||
fn pieces(self) -> (Annotations<Self>, Value<Self>) {
|
||||
match Arc::try_unwrap(self.0) {
|
||||
Ok(AnnotatedValue(anns, v)) => (anns, v),
|
||||
Err(r) => (r.0.clone(), r.1.clone()),
|
||||
}
|
||||
}
|
||||
|
||||
fn value_owned(self) -> Value<Self, IOValue> {
|
||||
fn value_owned(self) -> Value<Self> {
|
||||
match Arc::try_unwrap(self.0) {
|
||||
Ok(AnnotatedValue(_anns, v)) => v,
|
||||
Err(r) => r.1.clone(),
|
||||
|
@ -1269,7 +1276,7 @@ impl<'de> serde::Deserialize<'de> for IOValue {
|
|||
//---------------------------------------------------------------------------
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||
pub struct DummyValue<D: Embeddable>(AnnotatedValue<DummyValue<D>, D>);
|
||||
pub struct DummyValue<D: Embeddable>(AnnotatedValue<DummyValue<D>>);
|
||||
|
||||
impl<D: Embeddable> Debug for DummyValue<D> {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
|
@ -1277,31 +1284,32 @@ impl<D: Embeddable> Debug for DummyValue<D> {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
impl<D: Embeddable> DummyValue<D> {
|
||||
pub fn new() -> Self {
|
||||
DummyValue(AnnotatedValue::new(Annotations::empty(), Value::Boolean(false)))
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: Embeddable> NestedValue<D> for DummyValue<D> {
|
||||
fn wrap(_anns: Annotations<Self, D>, _v: Value<Self, D>) -> Self {
|
||||
impl<D: Embeddable> NestedValue for DummyValue<D> {
|
||||
type D = D;
|
||||
|
||||
fn wrap(_anns: Annotations<Self>, _v: Value<Self>) -> Self {
|
||||
DummyValue::new()
|
||||
}
|
||||
|
||||
fn annotations(&self) -> &Annotations<Self, D> {
|
||||
fn annotations(&self) -> &Annotations<Self> {
|
||||
&self.0.0
|
||||
}
|
||||
|
||||
fn value(&self) -> &Value<Self, D> {
|
||||
fn value(&self) -> &Value<Self> {
|
||||
&self.0.1
|
||||
}
|
||||
|
||||
fn pieces(self) -> (Annotations<Self, D>, Value<Self, D>) {
|
||||
fn pieces(self) -> (Annotations<Self>, Value<Self>) {
|
||||
(self.0.0, self.0.1)
|
||||
}
|
||||
|
||||
fn value_owned(self) -> Value<Self, D> {
|
||||
fn value_owned(self) -> Value<Self> {
|
||||
self.0.1
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,9 +8,9 @@ use crate::value::reader::BytesBinarySource;
|
|||
|
||||
use std::io;
|
||||
|
||||
use super::{DomainParse, Embeddable, IOValue, IOValueDomainCodec, NestedValue, Reader, ViaCodec};
|
||||
use super::{DomainParse, IOValue, IOValueDomainCodec, NestedValue, Reader, ViaCodec};
|
||||
|
||||
pub fn from_str<D: Embeddable, N: NestedValue<D>, Dec: DomainParse<D>>(
|
||||
pub fn from_str<N: NestedValue, Dec: DomainParse<N::D>>(
|
||||
s: &str,
|
||||
decode_embedded: Dec,
|
||||
) -> io::Result<N> {
|
||||
|
@ -21,7 +21,7 @@ pub fn iovalue_from_str(s: &str) -> io::Result<IOValue> {
|
|||
from_str(s, ViaCodec::new(IOValueDomainCodec))
|
||||
}
|
||||
|
||||
pub fn annotated_from_str<D: Embeddable, N: NestedValue<D>, Dec: DomainParse<D>>(
|
||||
pub fn annotated_from_str<N: NestedValue, Dec: DomainParse<N::D>>(
|
||||
s: &str,
|
||||
decode_embedded: Dec,
|
||||
) -> io::Result<N> {
|
||||
|
|
|
@ -50,7 +50,9 @@ fn append_codepoint(bs: &mut Vec<u8>, n: u32) -> io::Result<()> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
impl<'de, 'src, D: Embeddable, Dec: DomainParse<D>, S: BinarySource<'de>> TextReader<'de, 'src, D, Dec, S> {
|
||||
impl<'de, 'src, D: Embeddable, Dec: DomainParse<D>, S: BinarySource<'de>>
|
||||
TextReader<'de, 'src, D, Dec, S>
|
||||
{
|
||||
pub fn new(source: &'src mut S, dec: Dec) -> Self {
|
||||
TextReader {
|
||||
source,
|
||||
|
@ -87,14 +89,14 @@ impl<'de, 'src, D: Embeddable, Dec: DomainParse<D>, S: BinarySource<'de>> TextRe
|
|||
}
|
||||
|
||||
// TODO: This is a duplicate of fn expected in PackedReader.
|
||||
fn expected<N: NestedValue<D>>(&mut self, k: ExpectedKind) -> Error {
|
||||
match Reader::<D, N>::demand_next(self, true) {
|
||||
fn expected<N: NestedValue<D = D>>(&mut self, k: ExpectedKind) -> Error {
|
||||
match Reader::<N>::demand_next(self, true) {
|
||||
Ok(v) => Error::Expected(k, Received::ReceivedOtherValue(format!("{:?}", v))),
|
||||
Err(e) => e.into()
|
||||
}
|
||||
}
|
||||
|
||||
fn gather_annotations<N: NestedValue<D>>(&mut self) -> ReaderResult<Vec<N>> {
|
||||
fn gather_annotations<N: NestedValue<D = D>>(&mut self) -> ReaderResult<Vec<N>> {
|
||||
let mut vs = Vec::new();
|
||||
loop {
|
||||
self.skip_whitespace();
|
||||
|
@ -111,7 +113,7 @@ impl<'de, 'src, D: Embeddable, Dec: DomainParse<D>, S: BinarySource<'de>> TextRe
|
|||
self.skip_whitespace();
|
||||
match self.peek()? {
|
||||
b';' => { self.skip()?; self.comment_line()?; },
|
||||
b'@' => { self.skip()?; Reader::<D, DummyValue<D>>::skip_value(self)?; },
|
||||
b'@' => { self.skip()?; Reader::<DummyValue<D>>::skip_value(self)?; },
|
||||
_ => return Ok(()),
|
||||
}
|
||||
}
|
||||
|
@ -135,7 +137,7 @@ impl<'de, 'src, D: Embeddable, Dec: DomainParse<D>, S: BinarySource<'de>> TextRe
|
|||
}
|
||||
}
|
||||
|
||||
fn read_intpart<N: NestedValue<D>>(&mut self, mut bs: Vec<u8>, c: u8) -> io::Result<N> {
|
||||
fn read_intpart<N: NestedValue>(&mut self, mut bs: Vec<u8>, c: u8) -> io::Result<N> {
|
||||
match c {
|
||||
b'0' => {
|
||||
bs.push(c);
|
||||
|
@ -148,7 +150,7 @@ impl<'de, 'src, D: Embeddable, Dec: DomainParse<D>, S: BinarySource<'de>> TextRe
|
|||
}
|
||||
}
|
||||
|
||||
fn read_fracexp<N: NestedValue<D>>(&mut self, mut bs: Vec<u8>) -> io::Result<N> {
|
||||
fn read_fracexp<N: NestedValue>(&mut self, mut bs: Vec<u8>) -> io::Result<N> {
|
||||
let mut is_float = false;
|
||||
match self.peek() {
|
||||
Ok(b'.') => {
|
||||
|
@ -168,7 +170,7 @@ impl<'de, 'src, D: Embeddable, Dec: DomainParse<D>, S: BinarySource<'de>> TextRe
|
|||
}
|
||||
}
|
||||
|
||||
fn read_sign_and_exp<N: NestedValue<D>>(&mut self, mut bs: Vec<u8>) -> io::Result<N> {
|
||||
fn read_sign_and_exp<N: NestedValue>(&mut self, mut bs: Vec<u8>) -> io::Result<N> {
|
||||
match self.peek()? {
|
||||
b'+' | b'-' => bs.push(self.next_byte()?),
|
||||
_ => (),
|
||||
|
@ -178,7 +180,7 @@ impl<'de, 'src, D: Embeddable, Dec: DomainParse<D>, S: BinarySource<'de>> TextRe
|
|||
self.finish_number(bs, true)
|
||||
}
|
||||
|
||||
fn finish_number<N: NestedValue<D>>(&mut self, bs: Vec<u8>, is_float: bool) -> io::Result<N> {
|
||||
fn finish_number<N: NestedValue>(&mut self, bs: Vec<u8>, is_float: bool) -> io::Result<N> {
|
||||
let s = decode_utf8(bs)?;
|
||||
if is_float {
|
||||
match self.peek() {
|
||||
|
@ -288,7 +290,7 @@ impl<'de, 'src, D: Embeddable, Dec: DomainParse<D>, S: BinarySource<'de>> TextRe
|
|||
})?)
|
||||
}
|
||||
|
||||
fn read_literal_binary<N: NestedValue<D>>(&mut self) -> io::Result<N> {
|
||||
fn read_literal_binary<N: NestedValue>(&mut self) -> io::Result<N> {
|
||||
Ok(N::new(&self.read_stringlike(
|
||||
Vec::new(),
|
||||
|bs, b| Ok(bs.push(b)),
|
||||
|
@ -297,7 +299,7 @@ impl<'de, 'src, D: Embeddable, Dec: DomainParse<D>, S: BinarySource<'de>> TextRe
|
|||
|bs, r| Ok(bs.push(r.hexnum(2)? as u8)))?[..]))
|
||||
}
|
||||
|
||||
fn read_hex_binary<N: NestedValue<D>>(&mut self) -> io::Result<N> {
|
||||
fn read_hex_binary<N: NestedValue>(&mut self) -> io::Result<N> {
|
||||
let mut s = String::new();
|
||||
loop {
|
||||
self.skip_whitespace();
|
||||
|
@ -315,7 +317,7 @@ impl<'de, 'src, D: Embeddable, Dec: DomainParse<D>, S: BinarySource<'de>> TextRe
|
|||
}
|
||||
}
|
||||
|
||||
fn read_base64_binary<N: NestedValue<D>>(&mut self) -> io::Result<N> {
|
||||
fn read_base64_binary<N: NestedValue>(&mut self) -> io::Result<N> {
|
||||
let mut bs = Vec::new();
|
||||
loop {
|
||||
self.skip_whitespace();
|
||||
|
@ -332,7 +334,7 @@ impl<'de, 'src, D: Embeddable, Dec: DomainParse<D>, S: BinarySource<'de>> TextRe
|
|||
}
|
||||
}
|
||||
|
||||
fn upto<N: NestedValue<D>>(&mut self, delimiter: u8, read_annotations: bool) -> io::Result<Vec<N>> {
|
||||
fn upto<N: NestedValue<D = D>>(&mut self, delimiter: u8, read_annotations: bool) -> io::Result<Vec<N>> {
|
||||
let mut vs = Vec::new();
|
||||
loop {
|
||||
self.skip_whitespace();
|
||||
|
@ -340,11 +342,11 @@ impl<'de, 'src, D: Embeddable, Dec: DomainParse<D>, S: BinarySource<'de>> TextRe
|
|||
self.skip()?;
|
||||
return Ok(vs);
|
||||
}
|
||||
vs.push(Reader::<D, N>::demand_next(self, read_annotations)?);
|
||||
vs.push(Reader::<N>::demand_next(self, read_annotations)?);
|
||||
}
|
||||
}
|
||||
|
||||
fn read_dictionary<N: NestedValue<D>>(&mut self, read_annotations: bool) -> io::Result<N> {
|
||||
fn read_dictionary<N: NestedValue<D = D>>(&mut self, read_annotations: bool) -> io::Result<N> {
|
||||
let mut d = Map::new();
|
||||
loop {
|
||||
self.skip_whitespace();
|
||||
|
@ -352,17 +354,17 @@ impl<'de, 'src, D: Embeddable, Dec: DomainParse<D>, S: BinarySource<'de>> TextRe
|
|||
self.skip()?;
|
||||
return Ok(N::new(d));
|
||||
}
|
||||
let k = Reader::<D, N>::demand_next(self, read_annotations)?;
|
||||
let k = Reader::<N>::demand_next(self, read_annotations)?;
|
||||
self.skip_whitespace();
|
||||
if self.next_byte()? != b':' {
|
||||
return Err(io_syntax_error("Missing expected key/value separator"));
|
||||
}
|
||||
let v = Reader::<D, N>::demand_next(self, read_annotations)?;
|
||||
let v = Reader::<N>::demand_next(self, read_annotations)?;
|
||||
d.insert(k, v);
|
||||
}
|
||||
}
|
||||
|
||||
fn read_raw_symbol<N: NestedValue<D>>(&mut self, mut bs: Vec<u8>) -> io::Result<N> {
|
||||
fn read_raw_symbol<N: NestedValue>(&mut self, mut bs: Vec<u8>) -> io::Result<N> {
|
||||
loop {
|
||||
let c = match self.peek() {
|
||||
Err(e) if is_eof_io_error(&e) => b' ',
|
||||
|
@ -383,8 +385,8 @@ impl<'de, 'src, D: Embeddable, Dec: DomainParse<D>, S: BinarySource<'de>> TextRe
|
|||
}
|
||||
}
|
||||
|
||||
impl<'de, 'src, D: Embeddable, N: NestedValue<D>, Dec: DomainParse<D>, S: BinarySource<'de>>
|
||||
Reader<'de, D, N> for TextReader<'de, 'src, D, Dec, S>
|
||||
impl<'de, 'src, N: NestedValue, Dec: DomainParse<N::D>, S: BinarySource<'de>>
|
||||
Reader<'de, N> for TextReader<'de, 'src, N::D, Dec, S>
|
||||
{
|
||||
fn next(&mut self, read_annotations: bool) -> io::Result<Option<N>> {
|
||||
self.skip_whitespace();
|
||||
|
@ -415,7 +417,7 @@ impl<'de, 'src, D: Embeddable, N: NestedValue<D>, Dec: DomainParse<D>, S: Binary
|
|||
if read_annotations {
|
||||
let mut annotations = self.gather_annotations()?;
|
||||
let (existing_annotations, v) =
|
||||
Reader::<D, N>::demand_next(self, read_annotations)?.pieces();
|
||||
Reader::<N>::demand_next(self, read_annotations)?.pieces();
|
||||
annotations.extend_from_slice(existing_annotations.slice());
|
||||
N::wrap(Annotations::new(Some(annotations)), v)
|
||||
} else {
|
||||
|
@ -491,13 +493,13 @@ impl<'de, 'src, D: Embeddable, N: NestedValue<D>, Dec: DomainParse<D>, S: Binary
|
|||
if self.peek()? != b'<' { return Err(self.expected::<N>(ExpectedKind::Record(arity))); }
|
||||
self.skip()?;
|
||||
let mut b = B::Type::default();
|
||||
Reader::<D, N>::ensure_more_expected(self, &mut b, &B::Item::RecordLabel)?;
|
||||
Reader::<N>::ensure_more_expected(self, &mut b, &B::Item::RecordLabel)?;
|
||||
Ok(b)
|
||||
}
|
||||
|
||||
fn open_sequence_or_set(&mut self) -> ReaderResult<B::Item> {
|
||||
self.skip_annotations()?;
|
||||
let mark = Reader::<D, N>::mark(self)?;
|
||||
let mark = Reader::<N>::mark(self)?;
|
||||
match self.next_byte()? {
|
||||
b'#' => match self.next_byte()? {
|
||||
b'{' => return Ok(B::Item::SetValue),
|
||||
|
@ -506,7 +508,7 @@ impl<'de, 'src, D: Embeddable, N: NestedValue<D>, Dec: DomainParse<D>, S: Binary
|
|||
b'[' => return Ok(B::Item::SequenceValue),
|
||||
_ => (),
|
||||
}
|
||||
Reader::<D, N>::restore(self, &mark)?;
|
||||
Reader::<N>::restore(self, &mark)?;
|
||||
Err(self.expected::<N>(ExpectedKind::SequenceOrSet))
|
||||
}
|
||||
|
||||
|
@ -519,7 +521,7 @@ impl<'de, 'src, D: Embeddable, N: NestedValue<D>, Dec: DomainParse<D>, S: Binary
|
|||
|
||||
fn open_set(&mut self) -> ReaderResult<()> {
|
||||
self.skip_annotations()?;
|
||||
let mark = Reader::<D, N>::mark(self)?;
|
||||
let mark = Reader::<N>::mark(self)?;
|
||||
match self.next_byte()? {
|
||||
b'#' => match self.next_byte()? {
|
||||
b'{' => return Ok(()),
|
||||
|
@ -527,7 +529,7 @@ impl<'de, 'src, D: Embeddable, N: NestedValue<D>, Dec: DomainParse<D>, S: Binary
|
|||
},
|
||||
_ => (),
|
||||
}
|
||||
Reader::<D, N>::restore(self, &mark)?;
|
||||
Reader::<N>::restore(self, &mark)?;
|
||||
Err(self.expected::<N>(ExpectedKind::Set))
|
||||
}
|
||||
|
||||
|
@ -564,7 +566,7 @@ impl<'de, 'src, D: Embeddable, N: NestedValue<D>, Dec: DomainParse<D>, S: Binary
|
|||
}
|
||||
_ => {
|
||||
b.shift(Some(i.clone()));
|
||||
Reader::<D, N>::boundary(self, b)?;
|
||||
Reader::<N>::boundary(self, b)?;
|
||||
Ok(false)
|
||||
}
|
||||
}
|
||||
|
@ -572,7 +574,7 @@ impl<'de, 'src, D: Embeddable, N: NestedValue<D>, Dec: DomainParse<D>, S: Binary
|
|||
|
||||
fn open_embedded(&mut self) -> ReaderResult<()> {
|
||||
self.skip_annotations()?;
|
||||
let mark = Reader::<D, N>::mark(self)?;
|
||||
let mark = Reader::<N>::mark(self)?;
|
||||
match self.next_byte()? {
|
||||
b'#' => match self.next_byte()? {
|
||||
b'!' => return Ok(()),
|
||||
|
@ -580,7 +582,7 @@ impl<'de, 'src, D: Embeddable, N: NestedValue<D>, Dec: DomainParse<D>, S: Binary
|
|||
},
|
||||
_ => (),
|
||||
}
|
||||
Reader::<D, N>::restore(self, &mark)?;
|
||||
Reader::<N>::restore(self, &mark)?;
|
||||
Err(self.expected::<N>(ExpectedKind::Embedded))
|
||||
}
|
||||
|
||||
|
@ -598,9 +600,9 @@ impl<'de, 'src, D: Embeddable, N: NestedValue<D>, Dec: DomainParse<D>, S: Binary
|
|||
self.source.restore(mark)
|
||||
}
|
||||
|
||||
fn next_token(&mut self, read_embedded_annotations: bool) -> io::Result<Token<D, N>> {
|
||||
fn next_token(&mut self, read_embedded_annotations: bool) -> io::Result<Token<N>> {
|
||||
self.skip_annotations()?;
|
||||
let mark = Reader::<D, N>::mark(self)?;
|
||||
let mark = Reader::<N>::mark(self)?;
|
||||
Ok(match self.next_byte()? {
|
||||
b'<' => Token::Compound(CompoundClass::Record),
|
||||
b'[' => Token::Compound(CompoundClass::Sequence),
|
||||
|
@ -615,18 +617,18 @@ impl<'de, 'src, D: Embeddable, N: NestedValue<D>, Dec: DomainParse<D>, S: Binary
|
|||
}
|
||||
b'{' => Token::Compound(CompoundClass::Set),
|
||||
_ => {
|
||||
Reader::<D, N>::restore(self, &mark)?;
|
||||
Reader::<N>::restore(self, &mark)?;
|
||||
Token::Atom(self.demand_next(false)?)
|
||||
}
|
||||
},
|
||||
_ => {
|
||||
Reader::<D, N>::restore(self, &mark)?;
|
||||
Reader::<N>::restore(self, &mark)?;
|
||||
Token::Atom(self.demand_next(false)?)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn next_annotations_and_token(&mut self) -> io::Result<(Vec<N>, Token<D, N>)> {
|
||||
fn next_annotations_and_token(&mut self) -> io::Result<(Vec<N>, Token<N>)> {
|
||||
let annotations = self.gather_annotations()?;
|
||||
Ok((annotations, self.next_token(true)?))
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use crate::value::DomainEncode;
|
||||
use crate::value::Embeddable;
|
||||
use crate::value::IOValue;
|
||||
use crate::value::IOValueDomainCodec;
|
||||
use crate::value::NestedValue;
|
||||
|
@ -35,7 +34,7 @@ impl std::default::Default for CommaStyle {
|
|||
}
|
||||
|
||||
impl TextWriter<&mut Vec<u8>> {
|
||||
pub fn encode<D: Embeddable, N: NestedValue<D>, Enc: DomainEncode<D>>(
|
||||
pub fn encode<N: NestedValue, Enc: DomainEncode<N::D>>(
|
||||
enc: &mut Enc,
|
||||
v: &N,
|
||||
) -> io::Result<String> {
|
||||
|
|
|
@ -3,7 +3,7 @@ use std::io;
|
|||
use super::DomainEncode;
|
||||
use super::boundary as B;
|
||||
use super::signed_integer::SignedIntegerRepr;
|
||||
use super::repr::{Embeddable, Value, NestedValue, Float, Double};
|
||||
use super::repr::{Value, NestedValue, Float, Double};
|
||||
|
||||
pub trait CompoundWriter: Writer {
|
||||
fn boundary(&mut self, b: &B::Type) -> io::Result<()>;
|
||||
|
@ -58,7 +58,7 @@ pub trait Writer: Sized {
|
|||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
fn write<D: Embeddable, N: NestedValue<D>, Enc: DomainEncode<D>>(
|
||||
fn write<N: NestedValue, Enc: DomainEncode<N::D>>(
|
||||
&mut self,
|
||||
enc: &mut Enc,
|
||||
v: &N,
|
||||
|
@ -86,10 +86,10 @@ pub trait Writer: Sized {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn write_value<D: Embeddable, N: NestedValue<D>, Enc: DomainEncode<D>>(
|
||||
fn write_value<N: NestedValue, Enc: DomainEncode<N::D>>(
|
||||
&mut self,
|
||||
enc: &mut Enc,
|
||||
v: &Value<N, D>,
|
||||
v: &Value<N>,
|
||||
) -> io::Result<()> {
|
||||
match v {
|
||||
Value::Boolean(b) => self.write_bool(*b),
|
||||
|
|
Loading…
Reference in New Issue