From 8369d9c4f6e60006c6d7a363bf75f9dc92a32dd7 Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Wed, 9 Nov 2022 09:37:00 +0100 Subject: [PATCH] Rename Value -> ValueImpl --- implementations/rust/oo/benches/codec.rs | 2 +- implementations/rust/oo/src/domain.rs | 2 +- implementations/rust/oo/src/lib.rs | 6 +- implementations/rust/oo/src/packed/writer.rs | 4 +- implementations/rust/oo/src/reader.rs | 4 +- implementations/rust/oo/src/repr.rs | 204 +++++++++---------- implementations/rust/oo/src/text/writer.rs | 6 +- implementations/rust/oo/src/writer.rs | 4 +- 8 files changed, 116 insertions(+), 116 deletions(-) diff --git a/implementations/rust/oo/benches/codec.rs b/implementations/rust/oo/benches/codec.rs index 90aa4dc..700e33e 100644 --- a/implementations/rust/oo/benches/codec.rs +++ b/implementations/rust/oo/benches/codec.rs @@ -6,7 +6,7 @@ use oo::IOValueDomainCodec; use oo::IOValues; use oo::PackedWriter; use oo::Reader; -use oo::Value; +use oo::ValueImpl; use oo::packed::annotated_iovalue_from_bytes; use std::fs::File; use std::io::Read; diff --git a/implementations/rust/oo/src/domain.rs b/implementations/rust/oo/src/domain.rs index b22e4a2..8380fd9 100644 --- a/implementations/rust/oo/src/domain.rs +++ b/implementations/rust/oo/src/domain.rs @@ -3,7 +3,7 @@ use std::io; use super::IOValue; use super::Reader; use super::Writer; -use super::Value; +use super::ValueImpl; pub trait Domain: std::fmt::Debug + Eq + std::hash::Hash + Ord + Clone { type Decode: DomainDecode + Default; diff --git a/implementations/rust/oo/src/lib.rs b/implementations/rust/oo/src/lib.rs index 839caed..84d1d10 100644 --- a/implementations/rust/oo/src/lib.rs +++ b/implementations/rust/oo/src/lib.rs @@ -33,7 +33,7 @@ pub use repr::NoValue; pub use repr::Record; pub use repr::Set; pub use repr::Symbol; -pub use repr::Value; +pub use repr::ValueImpl; pub use repr::copy_via; pub use repr::iovalue; pub use repr::owned; @@ -58,7 +58,7 @@ pub use writer::write_value; mod demo { use crate::*; - fn getit<'a>(d: &'a dyn Value, k: &str) -> Option<&'a dyn Value> { + fn getit<'a>(d: &'a dyn ValueImpl, k: &str) -> Option<&'a dyn ValueImpl> { d.get(&k) } @@ -74,7 +74,7 @@ mod demo { v.insert(owned(vec![1, 2, 3]), "{a: 1, b: 2}".parse().unwrap()); v.insert(owned(r2), "bbb".parse().unwrap()); v.insert(owned(r), "".parse().unwrap()); - let w: &dyn Value = &v; + let w: &dyn ValueImpl = &v; println!("GETw abc {:?}", w.get(&"abc")); println!("GETw 123 {:?}", w.get(&123)); println!("GETw qqq {:?}", w.get(&"qqq")); diff --git a/implementations/rust/oo/src/packed/writer.rs b/implementations/rust/oo/src/packed/writer.rs index bfff270..6566a36 100644 --- a/implementations/rust/oo/src/packed/writer.rs +++ b/implementations/rust/oo/src/packed/writer.rs @@ -4,7 +4,7 @@ use std::convert::TryInto; use std::io; use std::io::Write; use super::constants::Tag; -use crate::{boundary as B, Value, Domain, DomainEncode, IOValue, IOValueDomainCodec, Writer}; +use crate::{boundary as B, ValueImpl, Domain, DomainEncode, IOValue, IOValueDomainCodec, Writer}; struct Buffers { base: W, @@ -38,7 +38,7 @@ impl PackedWriter<&mut Vec> { #[inline(always)] pub fn encode>( enc: &mut Enc, - v: &dyn Value, + v: &dyn ValueImpl, ) -> io::Result> { let mut buf: Vec = Vec::new(); v.write(&mut PackedWriter::new(&mut buf), enc)?; diff --git a/implementations/rust/oo/src/reader.rs b/implementations/rust/oo/src/reader.rs index a142f51..a4213a8 100644 --- a/implementations/rust/oo/src/reader.rs +++ b/implementations/rust/oo/src/reader.rs @@ -20,7 +20,7 @@ use crate::repr::IOValue; use crate::repr::Map; use crate::repr::Record; use crate::repr::Set; -use crate::repr::Value; +use crate::repr::ValueImpl; use crate::repr::owned; pub type ReaderResult = std::result::Result; @@ -146,7 +146,7 @@ pub trait Reader<'de> { &mut self, read_annotations: bool, dec: &mut Dec, - ) -> io::Result>> + ) -> io::Result>> { let (anns, v) = match read_annotations { true => self.gather_annotations()?.ok_or_else(io_eof)?, diff --git a/implementations/rust/oo/src/repr.rs b/implementations/rust/oo/src/repr.rs index 47b8b78..4e30ae0 100644 --- a/implementations/rust/oo/src/repr.rs +++ b/implementations/rust/oo/src/repr.rs @@ -25,10 +25,10 @@ use crate::domain::{NoEmbeddedDomainCodec, DomainEncode, IOValueDomainCodec}; use super::float::{eq_f32, eq_f64, cmp_f32, cmp_f64}; -pub type PlainValue<'a, D = IOValue> = Box + 'a>; +pub type PlainValue<'a, D = IOValue> = Box + 'a>; /// Atomic values from the specification. -pub trait Value { +pub trait ValueImpl { fn write(&self, w: &mut dyn Writer, enc: &mut dyn DomainEncode) -> io::Result<()> { write_value(w, self, enc) } @@ -48,19 +48,19 @@ pub trait Value { fn as_symbol(&self) -> Option> { None } fn is_record(&self) -> bool { false } - fn label(&self) -> &dyn Value { panic!("Not a record") } + fn label(&self) -> &dyn ValueImpl { panic!("Not a record") } fn is_sequence(&self) -> bool { false } fn len(&self) -> usize { panic!("Has no length") } - fn index(&self, _i: usize) -> &dyn Value { panic!("Not indexable") } - fn iter(&self) -> Box> + '_> { panic!("Not iterable") } + fn index(&self, _i: usize) -> &dyn ValueImpl { panic!("Not indexable") } + fn iter(&self) -> Box> + '_> { panic!("Not iterable") } fn is_set(&self) -> bool { false } - fn has(&self, _v: &dyn Value) -> bool { false } + fn has(&self, _v: &dyn ValueImpl) -> bool { false } fn is_dictionary(&self) -> bool { false } - fn get(&self, _k: &dyn Value) -> Option<&dyn Value> { None } - fn entries(&self) -> Box, &dyn Value)> + '_> { panic!("Not a dictionary") } + fn get(&self, _k: &dyn ValueImpl) -> Option<&dyn ValueImpl> { None } + fn entries(&self) -> Box, &dyn ValueImpl)> + '_> { panic!("Not a dictionary") } fn is_embedded(&self) -> bool { false } fn embedded(&self) -> Cow<'_, D> { panic!("Not an embedded value") } @@ -70,24 +70,24 @@ pub trait Value { fn specialized(&self) -> Option<&dyn Any> { None } } -pub fn value>(v: &V) -> &dyn Value { +pub fn value>(v: &V) -> &dyn ValueImpl { v } -pub fn owned + 'static>(v: V) -> PlainValue<'static, D> { +pub fn owned + 'static>(v: V) -> PlainValue<'static, D> { Box::new(v) } -pub fn arcvalue + 'static>(v: V) -> ArcValue { +pub fn arcvalue + 'static>(v: V) -> ArcValue { ArcValue(Arc::new(v)) } -pub fn iovalue + 'static>(v: V) -> IOValue { +pub fn iovalue + 'static>(v: V) -> IOValue { IOValue(arcvalue(v)) } pub fn copy_via( - v: &dyn Value, + v: &dyn ValueImpl, f: &mut F, ) -> Result, Err> where @@ -120,13 +120,13 @@ where } } -impl<'a, D: Domain + 'static> From<&'a dyn Value> for PlainValue<'static, D> { - fn from(v: &'a dyn Value) -> Self { +impl<'a, D: Domain + 'static> From<&'a dyn ValueImpl> for PlainValue<'static, D> { + fn from(v: &'a dyn ValueImpl) -> Self { v.value_clone() } } -impl<'a, D: Domain, V: Value + ?Sized> Value for &'a V { +impl<'a, D: Domain, V: ValueImpl + ?Sized> ValueImpl for &'a V { fn write(&self, w: &mut dyn Writer, enc: &mut dyn DomainEncode) -> io::Result<()> { (*self).write(w, enc) } fn value_clone(&self) -> PlainValue<'static, D> where D: 'static { (*self).value_clone() } fn value_class(&self) -> ValueClass { (*self).value_class() } @@ -139,22 +139,22 @@ impl<'a, D: Domain, V: Value + ?Sized> Value for &'a V { fn as_bytestring(&self) -> Option> { (*self).as_bytestring() } fn as_symbol(&self) -> Option> { (*self).as_symbol() } fn is_record(&self) -> bool { (*self).is_record() } - fn label(&self) -> &dyn Value { (*self).label() } + fn label(&self) -> &dyn ValueImpl { (*self).label() } fn is_sequence(&self) -> bool { (*self).is_sequence() } fn len(&self) -> usize { (*self).len() } - fn index(&self, i: usize) -> &dyn Value { (*self).index(i) } - fn iter(&self) -> Box> + '_> { (*self).iter() } + fn index(&self, i: usize) -> &dyn ValueImpl { (*self).index(i) } + fn iter(&self) -> Box> + '_> { (*self).iter() } fn is_set(&self) -> bool { (*self).is_set() } - fn has(&self, v: &dyn Value) -> bool { (*self).has(v) } + fn has(&self, v: &dyn ValueImpl) -> bool { (*self).has(v) } fn is_dictionary(&self) -> bool { (*self).is_dictionary() } - fn get<'value>(&'value self, k: &dyn Value) -> Option<&'value dyn Value> { (*self).get(k) } - fn entries(&self) -> Box, &dyn Value)> + '_> { (*self).entries() } + fn get<'value>(&'value self, k: &dyn ValueImpl) -> Option<&'value dyn ValueImpl> { (*self).get(k) } + fn entries(&self) -> Box, &dyn ValueImpl)> + '_> { (*self).entries() } fn is_embedded(&self) -> bool { (*self).is_embedded() } fn embedded(&self) -> Cow<'_, D> { (*self).embedded() } fn annotations(&self) -> Option<&[IOValue]> { (*self).annotations() } } -impl<'a, D: Domain> Value for PlainValue<'a, D> { +impl<'a, D: Domain> ValueImpl for PlainValue<'a, D> { fn write(&self, w: &mut dyn Writer, enc: &mut dyn DomainEncode) -> io::Result<()> { self.as_ref().write(w, enc) } fn value_clone(&self) -> PlainValue<'static, D> where D: 'static { self.as_ref().value_clone() } fn value_class(&self) -> ValueClass { self.as_ref().value_class() } @@ -167,22 +167,22 @@ impl<'a, D: Domain> Value for PlainValue<'a, D> { fn as_bytestring(&self) -> Option> { self.as_ref().as_bytestring() } fn as_symbol(&self) -> Option> { self.as_ref().as_symbol() } fn is_record(&self) -> bool { self.as_ref().is_record() } - fn label(&self) -> &dyn Value { self.as_ref().label() } + fn label(&self) -> &dyn ValueImpl { self.as_ref().label() } fn is_sequence(&self) -> bool { self.as_ref().is_sequence() } fn len(&self) -> usize { self.as_ref().len() } - fn index(&self, i: usize) -> &dyn Value { self.as_ref().index(i) } - fn iter(&self) -> Box> + '_> { self.as_ref().iter() } + fn index(&self, i: usize) -> &dyn ValueImpl { self.as_ref().index(i) } + fn iter(&self) -> Box> + '_> { self.as_ref().iter() } fn is_set(&self) -> bool { self.as_ref().is_set() } - fn has(&self, v: &dyn Value) -> bool { self.as_ref().has(v) } + fn has(&self, v: &dyn ValueImpl) -> bool { self.as_ref().has(v) } fn is_dictionary(&self) -> bool { self.as_ref().is_dictionary() } - fn get<'value>(&'value self, k: &dyn Value) -> Option<&'value dyn Value> { self.as_ref().get(k) } - fn entries(&self) -> Box, &dyn Value)> + '_> { self.as_ref().entries() } + fn get<'value>(&'value self, k: &dyn ValueImpl) -> Option<&'value dyn ValueImpl> { self.as_ref().get(k) } + fn entries(&self) -> Box, &dyn ValueImpl)> + '_> { self.as_ref().entries() } fn is_embedded(&self) -> bool { self.as_ref().is_embedded() } fn embedded(&self) -> Cow<'_, D> { self.as_ref().embedded() } fn annotations(&self) -> Option<&[IOValue]> { self.as_ref().annotations() } } -impl<'a, D: Domain> Debug for dyn Value + 'a { +impl<'a, D: Domain> Debug for dyn ValueImpl + 'a { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { TextWriter::fmt_value(f, &mut DefaultDomainCodec, self).map_err(|_| std::fmt::Error) } @@ -196,7 +196,7 @@ impl<'a, Err: Into, D: Domain + FromStr + 'static> FromStr } } -impl<'a, D: Domain> Hash for dyn Value + 'a { +impl<'a, D: Domain> Hash for dyn ValueImpl + 'a { fn hash(&self, state: &mut H) { match self.value_class() { ValueClass::Atomic(a) => match a { @@ -233,8 +233,8 @@ impl<'a, D: Domain> Hash for dyn Value + 'a { } fn iters_eq<'a, D: Domain>( - mut i1: Box> + 'a>, - mut i2: Box> + 'a>, + mut i1: Box> + 'a>, + mut i2: Box> + 'a>, ) -> bool { loop { match i1.next() { @@ -247,7 +247,7 @@ fn iters_eq<'a, D: Domain>( } } -impl<'a, D: Domain> PartialEq for dyn Value + 'a { +impl<'a, D: Domain> PartialEq for dyn ValueImpl + 'a { fn eq(&self, other: &Self) -> bool { let cls = self.value_class(); if cls != other.value_class() { return false; } @@ -293,8 +293,8 @@ impl<'a, D: Domain> PartialEq for dyn Value + 'a { } fn iters_cmp<'a, D: Domain>( - mut i1: Box> + 'a>, - mut i2: Box> + 'a>, + mut i1: Box> + 'a>, + mut i2: Box> + 'a>, ) -> Ordering { loop { match i1.next() { @@ -313,7 +313,7 @@ fn iters_cmp<'a, D: Domain>( } } -impl<'a, D: Domain> Ord for dyn Value + 'a { +impl<'a, D: Domain> Ord for dyn ValueImpl + 'a { fn cmp(&self, other: &Self) -> Ordering { let cls = self.value_class(); cls.cmp(&other.value_class()).then_with(|| match cls { @@ -354,9 +354,9 @@ impl<'a, D: Domain> Ord for dyn Value + 'a { } } -impl<'a, D: Domain> Eq for dyn Value + 'a {} +impl<'a, D: Domain> Eq for dyn ValueImpl + 'a {} -impl<'a, D: Domain> PartialOrd for dyn Value + 'a { +impl<'a, D: Domain> PartialOrd for dyn ValueImpl + 'a { fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp(other)) } @@ -401,7 +401,7 @@ impl<'r, 'a> From<&'r Atom<'a>> for AtomClass { } } -impl<'a, D: Domain> Value for Atom<'a> { +impl<'a, D: Domain> ValueImpl for Atom<'a> { fn write(&self, w: &mut dyn Writer, _enc: &mut dyn DomainEncode) -> io::Result<()> { match self { Atom::Boolean(b) => w.write_bool(*b), @@ -468,20 +468,20 @@ impl FromStr for NoValue { } } -impl Value for NoValue { +impl ValueImpl for NoValue { fn write(&self, _w: &mut dyn Writer, _enc: &mut dyn DomainEncode) -> io::Result<()> { unreachable!() } fn value_clone(&self) -> PlainValue<'static, D> where D: 'static { unreachable!() } fn value_class(&self) -> ValueClass { unreachable!() } } -impl Value for bool { +impl ValueImpl for bool { fn write(&self, w: &mut dyn Writer, __enc: &mut dyn DomainEncode) -> io::Result<()> { w.write_bool(*self) } fn value_clone(&self) -> PlainValue<'static, D> where D: 'static { Box::new(*self) } fn value_class(&self) -> ValueClass { ValueClass::Atomic(AtomClass::Boolean) } fn as_boolean(&self) -> Option { Some(*self) } } -impl Value for u64 { +impl ValueImpl for u64 { fn write(&self, w: &mut dyn Writer, _enc: &mut dyn DomainEncode) -> io::Result<()> { w.write_u64(*self) } fn value_clone(&self) -> PlainValue<'static, D> where D: 'static { Box::new(*self) } fn value_class(&self) -> ValueClass { ValueClass::Atomic(AtomClass::SignedInteger) } @@ -490,7 +490,7 @@ impl Value for u64 { } } -impl Value for SignedInteger { +impl ValueImpl for SignedInteger { fn write(&self, w: &mut dyn Writer, _enc: &mut dyn DomainEncode) -> io::Result<()> { w.write_signed_integer(self) } fn value_clone(&self) -> PlainValue<'static, D> where D: 'static { Box::new(self.clone()) } fn value_class(&self) -> ValueClass { ValueClass::Atomic(AtomClass::SignedInteger) } @@ -499,7 +499,7 @@ impl Value for SignedInteger { } } -impl Value for f32 { +impl ValueImpl for f32 { fn write(&self, w: &mut dyn Writer, _enc: &mut dyn DomainEncode) -> io::Result<()> { w.write_f32(*self) } fn value_clone(&self) -> PlainValue<'static, D> where D: 'static { Box::new(*self) } fn value_class(&self) -> ValueClass { ValueClass::Atomic(AtomClass::Float) } @@ -507,7 +507,7 @@ impl Value for f32 { fn as_double(&self) -> Option { Some(*self as f64) } } -impl Value for f64 { +impl ValueImpl for f64 { fn write(&self, w: &mut dyn Writer, _enc: &mut dyn DomainEncode) -> io::Result<()> { w.write_f64(*self) } fn value_clone(&self) -> PlainValue<'static, D> where D: 'static { Box::new(*self) } fn value_class(&self) -> ValueClass { ValueClass::Atomic(AtomClass::Float) } @@ -515,14 +515,14 @@ impl Value for f64 { fn as_double(&self) -> Option { Some(*self) } } -impl Value for str { +impl ValueImpl for str { fn write(&self, w: &mut dyn Writer, _enc: &mut dyn DomainEncode) -> io::Result<()> { w.write_string(self) } fn value_clone(&self) -> PlainValue<'static, D> where D: 'static { Box::new(self.to_owned()) } fn value_class(&self) -> ValueClass { ValueClass::Atomic(AtomClass::String) } fn as_string(&self) -> Option> { Some(Cow::Borrowed(self)) } } -impl Value for String { +impl ValueImpl for String { fn write(&self, w: &mut dyn Writer, _enc: &mut dyn DomainEncode) -> io::Result<()> { w.write_string(self) } fn value_clone(&self) -> PlainValue<'static, D> where D: 'static { Box::new(self.clone()) } fn value_class(&self) -> ValueClass { ValueClass::Atomic(AtomClass::String) } @@ -539,7 +539,7 @@ impl + Debug> Bytes { } } -impl + Debug, D: Domain> Value for Bytes { +impl + Debug, D: Domain> ValueImpl for Bytes { fn write(&self, w: &mut dyn Writer, _enc: &mut dyn DomainEncode) -> io::Result<()> { w.write_bytes(self.0.as_ref()) } fn value_clone(&self) -> PlainValue<'static, D> where D: 'static { Box::new(Bytes(self.0.as_ref().to_owned())) } fn value_class(&self) -> ValueClass { ValueClass::Atomic(AtomClass::ByteString) } @@ -556,7 +556,7 @@ impl + Debug> Symbol { } } -impl + Debug, D: Domain> Value for Symbol { +impl + Debug, D: Domain> ValueImpl for Symbol { fn write(&self, w: &mut dyn Writer, _enc: &mut dyn DomainEncode) -> io::Result<()> { w.write_symbol(self.0.as_ref()) } fn value_clone(&self) -> PlainValue<'static, D> where D: 'static { Box::new(Symbol(self.0.as_ref().to_owned())) } fn value_class(&self) -> ValueClass { ValueClass::Atomic(AtomClass::Symbol) } @@ -583,7 +583,7 @@ impl Record { } } -impl> Value for Record { +impl> ValueImpl for Record { fn write(&self, w: &mut dyn Writer, enc: &mut dyn DomainEncode) -> io::Result<()> { w.start_record()?; let mut b = B::start(B::Item::RecordLabel); @@ -605,15 +605,15 @@ impl> Value for Record { fn value_class(&self) -> ValueClass { ValueClass::Compound(CompoundClass::Record) } fn is_record(&self) -> bool { true } - fn label(&self) -> &dyn Value { &self.0[0] } + fn label(&self) -> &dyn ValueImpl { &self.0[0] } fn len(&self) -> usize { self.0.len() - 1 } - fn index(&self, i: usize) -> &dyn Value { &self.0[i + 1] } - fn iter(&self) -> Box> + '_> { + fn index(&self, i: usize) -> &dyn ValueImpl { &self.0[i + 1] } + fn iter(&self) -> Box> + '_> { Box::new(self.0[1..].iter().map(value)) } } -impl> Value for Vec { +impl> ValueImpl for Vec { fn write(&self, w: &mut dyn Writer, enc: &mut dyn DomainEncode) -> io::Result<()> { (&self[..]).write(w, enc) } @@ -625,13 +625,13 @@ impl> Value for Vec { fn value_class(&self) -> ValueClass { ValueClass::Compound(CompoundClass::Sequence) } fn is_sequence(&self) -> bool { true } fn len(&self) -> usize { self.len() } - fn index(&self, i: usize) -> &dyn Value { &self[i] } - fn iter(&self) -> Box> + '_> { + fn index(&self, i: usize) -> &dyn ValueImpl { &self[i] } + fn iter(&self) -> Box> + '_> { Box::new(self[..].iter().map(value)) } } -impl> Value for [V] { +impl> ValueImpl for [V] { fn write(&self, w: &mut dyn Writer, enc: &mut dyn DomainEncode) -> io::Result<()> { w.start_sequence()?; let mut b = B::Type::default(); @@ -652,13 +652,13 @@ impl> Value for [V] { fn value_class(&self) -> ValueClass { ValueClass::Compound(CompoundClass::Sequence) } fn is_sequence(&self) -> bool { true } fn len(&self) -> usize { self.len() } - fn index(&self, i: usize) -> &dyn Value { &self[i] } - fn iter(&self) -> Box> + '_> { + fn index(&self, i: usize) -> &dyn ValueImpl { &self[i] } + fn iter(&self) -> Box> + '_> { Box::new(self[..].iter().map(value)) } } -impl<'e, D: Domain, E: for<'a> Borrow> + Ord + 'e> Value for Set { +impl<'e, D: Domain, E: for<'a> Borrow> + Ord + 'e> ValueImpl for Set { fn write(&self, w: &mut dyn Writer, enc: &mut dyn DomainEncode) -> io::Result<()> { w.start_set()?; let mut b = B::Type::default(); @@ -679,8 +679,8 @@ impl<'e, D: Domain, E: for<'a> Borrow> + Ord + 'e> Value for Set ValueClass { ValueClass::Compound(CompoundClass::Set) } fn is_set(&self) -> bool { true } fn len(&self) -> usize { self.len() } - fn has(&self, v: &dyn Value) -> bool { self.contains(&Key::wrap_ref(v)) } - fn iter(&self) -> Box> + '_> { + fn has(&self, v: &dyn ValueImpl) -> bool { self.contains(&Key::wrap_ref(v)) } + fn iter(&self) -> Box> + '_> { Box::new(self.iter().map(|e| Key::peel_ref(&e.borrow()))) } } @@ -691,8 +691,8 @@ impl<'e, D: Domain, E: for<'a> Borrow> + Ord + 'e> Value for Set(pub dyn Value + 'a); -unsafe impl<'a, D: Domain> TransparentWrapper + 'a> for Key<'a, D> {} +pub struct Key<'a, D: Domain>(pub dyn ValueImpl + 'a); +unsafe impl<'a, D: Domain> TransparentWrapper + 'a> for Key<'a, D> {} impl<'a, 'b: 'a, D: Domain> Borrow> for PlainValue<'b, D> { fn borrow(&self) -> &Key<'a, D> { @@ -700,13 +700,13 @@ impl<'a, 'b: 'a, D: Domain> Borrow> for PlainValue<'b, D> { } } -impl<'a, 'b: 'a, D: Domain> Borrow> for &'b (dyn Value + 'b) { +impl<'a, 'b: 'a, D: Domain> Borrow> for &'b (dyn ValueImpl + 'b) { fn borrow(&self) -> &Key<'a, D> { Key::wrap_ref(self) } } -impl<'k, D: Domain, V: Value, K: for<'a> Borrow> + Ord + 'k> Value +impl<'k, D: Domain, V: ValueImpl, K: for<'a> Borrow> + Ord + 'k> ValueImpl for Map { fn write(&self, w: &mut dyn Writer, enc: &mut dyn DomainEncode) -> io::Result<()> { @@ -726,20 +726,20 @@ impl<'k, D: Domain, V: Value, K: for<'a> Borrow> + Ord + 'k> Value } fn value_clone(&self) -> PlainValue<'static, D> where D: 'static { - Box::new(Value::entries(self).map(|(k, v)| (k.value_clone(), v.value_clone())).collect::>()) + Box::new(ValueImpl::entries(self).map(|(k, v)| (k.value_clone(), v.value_clone())).collect::>()) } fn value_class(&self) -> ValueClass { ValueClass::Compound(CompoundClass::Dictionary) } fn is_dictionary(&self) -> bool { true } fn len(&self) -> usize { self.len() } - fn has(&self, v: &dyn Value) -> bool { self.contains_key(&Key::wrap_ref(v)) } - fn get(&self, k: &dyn Value) -> Option<&dyn Value> { + fn has(&self, v: &dyn ValueImpl) -> bool { self.contains_key(&Key::wrap_ref(v)) } + fn get(&self, k: &dyn ValueImpl) -> Option<&dyn ValueImpl> { match Map::get(self, &Key::wrap_ref(k)) { Some(v) => Some(v), None => None, } } - fn entries(&self) -> Box, &dyn Value)> + '_> { + fn entries(&self) -> Box, &dyn ValueImpl)> + '_> { Box::new(self.iter().map(|(k,v)| (Key::peel_ref(&k.borrow()), value(v)))) } } @@ -762,7 +762,7 @@ impl Embedded { } } -impl Value for Embedded { +impl ValueImpl for Embedded { fn write(&self, w: &mut dyn Writer, enc: &mut dyn DomainEncode) -> io::Result<()> { w.start_embedded()?; enc.encode_embedded(w, &self.0)?; @@ -776,19 +776,19 @@ impl Value for Embedded { } #[derive(Debug)] -pub struct Annotations>(V, Vec, PhantomData); +pub struct Annotations>(V, Vec, PhantomData); -impl> Annotations { +impl> Annotations { pub fn new(value: V, anns: Vec) -> Self { Annotations(value, anns, PhantomData) } - pub fn value(&self) -> &dyn Value { + pub fn value(&self) -> &dyn ValueImpl { &self.0 } } -impl> Value for Annotations { +impl> ValueImpl for Annotations { fn write(&self, w: &mut dyn Writer, enc: &mut dyn DomainEncode) -> io::Result<()> { if !self.1.is_empty() { w.start_annotations()?; @@ -825,42 +825,42 @@ impl> Value for Annotations { fn as_bytestring(&self) -> Option> { self.value().as_bytestring() } fn as_symbol(&self) -> Option> { self.value().as_symbol() } fn is_record(&self) -> bool { self.value().is_record() } - fn label(&self) -> &dyn Value { self.value().label() } + fn label(&self) -> &dyn ValueImpl { self.value().label() } fn is_sequence(&self) -> bool { self.value().is_sequence() } fn len(&self) -> usize { self.value().len() } - fn index(&self, i: usize) -> &dyn Value { self.value().index(i) } - fn iter(&self) -> Box> + '_> { self.value().iter() } + fn index(&self, i: usize) -> &dyn ValueImpl { self.value().index(i) } + fn iter(&self) -> Box> + '_> { self.value().iter() } fn is_set(&self) -> bool { self.value().is_set() } - fn has(&self, v: &dyn Value) -> bool { self.value().has(v) } + fn has(&self, v: &dyn ValueImpl) -> bool { self.value().has(v) } fn is_dictionary(&self) -> bool { self.value().is_dictionary() } - fn get(&self, k: &dyn Value) -> Option<&dyn Value> { self.value().get(k) } - fn entries(&self) -> Box, &dyn Value)> + '_> { self.value().entries() } + fn get(&self, k: &dyn ValueImpl) -> Option<&dyn ValueImpl> { self.value().get(k) } + fn entries(&self) -> Box, &dyn ValueImpl)> + '_> { self.value().entries() } fn is_embedded(&self) -> bool { self.value().is_embedded() } fn embedded(&self) -> Cow<'_, D> { self.value().embedded() } fn annotations(&self) -> Option<&[IOValue]> { Some(&self.1) } } -impl> PartialEq for Annotations { +impl> PartialEq for Annotations { fn eq(&self, other: &Self) -> bool { self.value().eq(&other.value()) } } -impl> Eq for Annotations {} +impl> Eq for Annotations {} -impl> Hash for Annotations { +impl> Hash for Annotations { fn hash(&self, state: &mut H) { self.value().hash(state); } } -impl> PartialOrd for Annotations { +impl> PartialOrd for Annotations { fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp(other)) } } -impl> Ord for Annotations { +impl> Ord for Annotations { fn cmp(&self, other: &Self) -> Ordering { self.value().cmp(&other.value()) } @@ -868,7 +868,7 @@ impl> Ord for Annotations { #[derive(Clone, Eq, Hash, PartialOrd, Ord)] #[repr(transparent)] -pub struct ArcValue(Arc>); +pub struct ArcValue(Arc>); #[derive(Clone, PartialEq, Eq, Hash, PartialOrd, Ord)] #[repr(transparent)] @@ -938,7 +938,7 @@ impl<'a, D: Domain> Borrow> for ArcValue { } } -impl Value for ArcValue { +impl ValueImpl for ArcValue { fn write(&self, w: &mut dyn Writer, enc: &mut dyn DomainEncode) -> io::Result<()> { self.0.write(w, enc) } fn value_clone(&self) -> PlainValue<'static, D> { Box::new(self.clone()) } fn value_class(&self) -> ValueClass { self.0.value_class() } @@ -951,22 +951,22 @@ impl Value for ArcValue { fn as_bytestring(&self) -> Option> { self.0.as_bytestring() } fn as_symbol(&self) -> Option> { self.0.as_symbol() } fn is_record(&self) -> bool { self.0.is_record() } - fn label(&self) -> &dyn Value { self.0.label() } + fn label(&self) -> &dyn ValueImpl { self.0.label() } fn is_sequence(&self) -> bool { self.0.is_sequence() } fn len(&self) -> usize { self.0.len() } - fn index(&self, i: usize) -> &dyn Value { self.0.index(i) } - fn iter(&self) -> Box> + '_> { self.0.iter() } + fn index(&self, i: usize) -> &dyn ValueImpl { self.0.index(i) } + fn iter(&self) -> Box> + '_> { self.0.iter() } fn is_set(&self) -> bool { self.0.is_set() } - fn has(&self, v: &dyn Value) -> bool { self.0.has(v) } + fn has(&self, v: &dyn ValueImpl) -> bool { self.0.has(v) } fn is_dictionary(&self) -> bool { self.0.is_dictionary() } - fn get<'value>(&'value self, k: &dyn Value) -> Option<&'value dyn Value> { self.0.get(k) } - fn entries(&self) -> Box, &dyn Value)> + '_> { self.0.entries() } + fn get<'value>(&'value self, k: &dyn ValueImpl) -> Option<&'value dyn ValueImpl> { self.0.get(k) } + fn entries(&self) -> Box, &dyn ValueImpl)> + '_> { self.0.entries() } fn is_embedded(&self) -> bool { self.0.is_embedded() } fn embedded(&self) -> Cow<'_, D> { self.0.embedded() } fn annotations(&self) -> Option<&[IOValue]> { self.0.annotations() } } -impl Value for IOValue { +impl ValueImpl for IOValue { fn write(&self, w: &mut dyn Writer, enc: &mut dyn DomainEncode) -> io::Result<()> { self.0.write(w, enc) } fn value_clone(&self) -> PlainValue<'static, IOValue> { Box::new(self.clone()) } fn value_class(&self) -> ValueClass { self.0.value_class() } @@ -979,16 +979,16 @@ impl Value for IOValue { fn as_bytestring(&self) -> Option> { self.0.as_bytestring() } fn as_symbol(&self) -> Option> { self.0.as_symbol() } fn is_record(&self) -> bool { self.0.is_record() } - fn label(&self) -> &dyn Value { self.0.label() } + fn label(&self) -> &dyn ValueImpl { self.0.label() } fn is_sequence(&self) -> bool { self.0.is_sequence() } fn len(&self) -> usize { self.0.len() } - fn index(&self, i: usize) -> &dyn Value { self.0.index(i) } - fn iter(&self) -> Box> + '_> { self.0.iter() } + fn index(&self, i: usize) -> &dyn ValueImpl { self.0.index(i) } + fn iter(&self) -> Box> + '_> { self.0.iter() } fn is_set(&self) -> bool { self.0.is_set() } - fn has(&self, v: &dyn Value) -> bool { self.0.has(v) } + fn has(&self, v: &dyn ValueImpl) -> bool { self.0.has(v) } fn is_dictionary(&self) -> bool { self.0.is_dictionary() } - fn get<'value>(&'value self, k: &dyn Value) -> Option<&'value dyn Value> { self.0.get(k) } - fn entries(&self) -> Box, &dyn Value)> + '_> { self.0.entries() } + fn get<'value>(&'value self, k: &dyn ValueImpl) -> Option<&'value dyn ValueImpl> { self.0.get(k) } + fn entries(&self) -> Box, &dyn ValueImpl)> + '_> { self.0.entries() } fn is_embedded(&self) -> bool { self.0.is_embedded() } fn embedded(&self) -> Cow<'_, IOValue> { self.0.embedded() } fn annotations(&self) -> Option<&[IOValue]> { self.0.annotations() } diff --git a/implementations/rust/oo/src/text/writer.rs b/implementations/rust/oo/src/text/writer.rs index d7791dd..1e8afbb 100644 --- a/implementations/rust/oo/src/text/writer.rs +++ b/implementations/rust/oo/src/text/writer.rs @@ -2,7 +2,7 @@ use crate::Domain; use crate::DomainEncode; use crate::IOValue; use crate::IOValueDomainCodec; -use crate::Value; +use crate::ValueImpl; use crate::Writer; use crate::hex::HexFormatter; @@ -39,7 +39,7 @@ impl TextWriter<&mut Vec> { pub fn fmt_value>( f: &mut std::fmt::Formatter<'_>, enc: &mut Enc, - v: &dyn Value, + v: &dyn ValueImpl, ) -> io::Result<()> { let mut buf: Vec = Vec::new(); let mut w = TextWriter::new(&mut buf); @@ -51,7 +51,7 @@ impl TextWriter<&mut Vec> { pub fn encode>( enc: &mut Enc, - v: &dyn Value, + v: &dyn ValueImpl, ) -> io::Result { let mut buf: Vec = Vec::new(); v.write(&mut TextWriter::new(&mut buf), enc)?; diff --git a/implementations/rust/oo/src/writer.rs b/implementations/rust/oo/src/writer.rs index a863c43..40b0c51 100644 --- a/implementations/rust/oo/src/writer.rs +++ b/implementations/rust/oo/src/writer.rs @@ -10,7 +10,7 @@ use crate::SignedInteger; use crate::ValueClass; use crate::boundary as B; use crate::signed_integer::SignedIntegerRepr; -use crate::Value; +use crate::ValueImpl; pub trait Writer { fn boundary(&mut self, b: &B::Type) -> io::Result<()>; @@ -68,7 +68,7 @@ pub trait Writer { } } -pub fn write_value>( +pub fn write_value>( w: &mut dyn Writer, v: V, enc: &mut dyn DomainEncode,