|
|
|
@ -1,12 +1,14 @@
|
|
|
|
|
use bytemuck::TransparentWrapper;
|
|
|
|
|
|
|
|
|
|
use std::any::Any;
|
|
|
|
|
use std::borrow::{Cow, Borrow};
|
|
|
|
|
use std::borrow::Borrow;
|
|
|
|
|
use std::borrow::Cow;
|
|
|
|
|
use std::cmp::Ordering;
|
|
|
|
|
use std::fmt::Debug;
|
|
|
|
|
use std::hash::{Hash, Hasher};
|
|
|
|
|
use std::io;
|
|
|
|
|
use std::marker::PhantomData;
|
|
|
|
|
use std::ops::Deref;
|
|
|
|
|
use std::str::FromStr;
|
|
|
|
|
use std::sync::Arc;
|
|
|
|
|
use std::vec::Vec;
|
|
|
|
@ -25,7 +27,88 @@ use crate::domain::{NoEmbeddedDomainCodec, DomainEncode, IOValueDomainCodec};
|
|
|
|
|
|
|
|
|
|
use super::float::{eq_f32, eq_f64, cmp_f32, cmp_f64};
|
|
|
|
|
|
|
|
|
|
pub type PlainValue<'a, D = IOValue> = Box<dyn ValueImpl<D> + 'a>;
|
|
|
|
|
pub type PlainValue<'va, D = IOValue> = Box<dyn ValueImpl<D> + 'va>;
|
|
|
|
|
|
|
|
|
|
pub enum Value<'r, D: Domain = IOValue> {
|
|
|
|
|
Borrowed(&'r (dyn ValueImpl<D> + 'r)),
|
|
|
|
|
Owned(PlainValue<'static, D>),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'r, D: Domain> Value<'r, D> {
|
|
|
|
|
pub fn into_owned(self: Value<'r, D>) -> PlainValue<'static, D> {
|
|
|
|
|
match self {
|
|
|
|
|
Value::Borrowed(r) => return r.value_clone(),
|
|
|
|
|
Value::Owned(v) => return v,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'r, 'va: 'r, D: Domain> From<&'r (dyn ValueImpl<D> + 'r)> for Value<'r, D> {
|
|
|
|
|
fn from(r: &'r (dyn ValueImpl<D> + 'r)) -> Self {
|
|
|
|
|
Value::Borrowed(r)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'r, D: Domain> From<PlainValue<'static, D>> for Value<'r, D> {
|
|
|
|
|
fn from(v: PlainValue<'static, D>) -> Self {
|
|
|
|
|
Value::Owned(v)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'r, D: Domain> Deref for Value<'r, D> {
|
|
|
|
|
type Target = dyn ValueImpl<D> + 'r;
|
|
|
|
|
|
|
|
|
|
fn deref(&self) -> &Self::Target {
|
|
|
|
|
match self {
|
|
|
|
|
Value::Borrowed(r) => r,
|
|
|
|
|
Value::Owned(v) => v,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'r, D: Domain> From<Value<'r, D>> for ArcValue<D> {
|
|
|
|
|
fn from(v: Value<'r, D>) -> Self {
|
|
|
|
|
v.into_owned().into()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'r> From<Value<'r, IOValue>> for IOValue {
|
|
|
|
|
fn from(v: Value<'r, IOValue>) -> Self {
|
|
|
|
|
v.into_owned().into()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'r, 'va: 'r, D: Domain> Debug for Value<'r, D> {
|
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
|
|
|
self.deref().fmt(f)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'r, 'va: 'r, D: Domain> PartialEq for Value<'r, D> {
|
|
|
|
|
fn eq(&self, other: &Self) -> bool {
|
|
|
|
|
&**self == &**other
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'r, 'va: 'r, D: Domain> Eq for Value<'r, D> {}
|
|
|
|
|
|
|
|
|
|
impl<'r, 'va: 'r, D: Domain> PartialOrd for Value<'r, D> {
|
|
|
|
|
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
|
|
|
|
Some((&**self).cmp(&**other))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'r, 'va: 'r, D: Domain> Ord for Value<'r, D> {
|
|
|
|
|
fn cmp(&self, other: &Self) -> Ordering {
|
|
|
|
|
(&**self).cmp(&**other)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'r, 'va: 'r, D: Domain> Hash for Value<'r, D> {
|
|
|
|
|
fn hash<H: Hasher>(&self, state: &mut H) {
|
|
|
|
|
(&**self).hash(state)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Atomic values from the specification.
|
|
|
|
|
pub trait ValueImpl<D: Domain> {
|
|
|
|
@ -33,7 +116,7 @@ pub trait ValueImpl<D: Domain> {
|
|
|
|
|
write_value(w, self, enc)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn value_clone(&self) -> PlainValue<'static, D> where D: 'static;
|
|
|
|
|
fn value_clone(&self) -> PlainValue<'static, D>;
|
|
|
|
|
fn value_class(&self) -> ValueClass;
|
|
|
|
|
|
|
|
|
|
fn as_boolean(&self) -> Option<bool> { None }
|
|
|
|
@ -48,19 +131,19 @@ pub trait ValueImpl<D: Domain> {
|
|
|
|
|
fn as_symbol(&self) -> Option<Cow<'_, str>> { None }
|
|
|
|
|
|
|
|
|
|
fn is_record(&self) -> bool { false }
|
|
|
|
|
fn label(&self) -> &dyn ValueImpl<D> { panic!("Not a record") }
|
|
|
|
|
fn label(&self) -> Value<'_, D> { panic!("Not a record") }
|
|
|
|
|
|
|
|
|
|
fn is_sequence(&self) -> bool { false }
|
|
|
|
|
fn len(&self) -> usize { panic!("Has no length") }
|
|
|
|
|
fn index(&self, _i: usize) -> &dyn ValueImpl<D> { panic!("Not indexable") }
|
|
|
|
|
fn iter(&self) -> Box<dyn Iterator<Item = &dyn ValueImpl<D>> + '_> { panic!("Not iterable") }
|
|
|
|
|
fn index(&self, _i: usize) -> Value<'_, D> { panic!("Not indexable") }
|
|
|
|
|
fn iter(&self) -> Box<dyn Iterator<Item = Value<'_, D>> + '_> { panic!("Not iterable") }
|
|
|
|
|
|
|
|
|
|
fn is_set(&self) -> bool { false }
|
|
|
|
|
fn has(&self, _v: &dyn ValueImpl<D>) -> bool { false }
|
|
|
|
|
|
|
|
|
|
fn is_dictionary(&self) -> bool { false }
|
|
|
|
|
fn get(&self, _k: &dyn ValueImpl<D>) -> Option<&dyn ValueImpl<D>> { None }
|
|
|
|
|
fn entries(&self) -> Box<dyn Iterator<Item = (&dyn ValueImpl<D>, &dyn ValueImpl<D>)> + '_> { panic!("Not a dictionary") }
|
|
|
|
|
fn get(&self, _k: &dyn ValueImpl<D>) -> Option<Value<'_, D>> { None }
|
|
|
|
|
fn entries(&self) -> Box<dyn Iterator<Item = (Value<'_, D>, Value<'_, D>)> + '_> { panic!("Not a dictionary") }
|
|
|
|
|
|
|
|
|
|
fn is_embedded(&self) -> bool { false }
|
|
|
|
|
fn embedded(&self) -> Cow<'_, D> { panic!("Not an embedded value") }
|
|
|
|
@ -70,11 +153,11 @@ pub trait ValueImpl<D: Domain> {
|
|
|
|
|
fn specialized(&self) -> Option<&dyn Any> { None }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn value<D: Domain, V: ValueImpl<D>>(v: &V) -> &dyn ValueImpl<D> {
|
|
|
|
|
v
|
|
|
|
|
pub fn value<D: Domain, V: ValueImpl<D>>(v: &V) -> Value<'_, D> {
|
|
|
|
|
Value::Borrowed(v)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn owned<D: Domain, V: ValueImpl<D> + 'static>(v: V) -> PlainValue<'static, D> {
|
|
|
|
|
pub fn owned<'va, D: Domain, V: ValueImpl<D> + 'static>(v: V) -> PlainValue<'va, D> {
|
|
|
|
|
Box::new(v)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -86,7 +169,7 @@ pub fn iovalue<V: ValueImpl<IOValue> + 'static>(v: V) -> IOValue {
|
|
|
|
|
IOValue(arcvalue(v))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn copy_via<D: Domain, E: Domain + 'static, F, Err>(
|
|
|
|
|
pub fn copy_via<D: Domain, E: Domain, F, Err>(
|
|
|
|
|
v: &dyn ValueImpl<D>,
|
|
|
|
|
f: &mut F,
|
|
|
|
|
) -> Result<PlainValue<'static, E>, Err>
|
|
|
|
@ -95,32 +178,32 @@ where
|
|
|
|
|
{
|
|
|
|
|
match v.value_class() {
|
|
|
|
|
ValueClass::Atomic(a) => Ok(match a {
|
|
|
|
|
AtomClass::Boolean => owned(v.as_boolean().unwrap()),
|
|
|
|
|
AtomClass::Float => owned(v.as_float().unwrap()),
|
|
|
|
|
AtomClass::Double => owned(v.as_double().unwrap()),
|
|
|
|
|
AtomClass::SignedInteger => owned(v.as_signed_integer().unwrap()),
|
|
|
|
|
AtomClass::String => owned(v.as_string().unwrap().into_owned()),
|
|
|
|
|
AtomClass::ByteString => owned(Bytes(v.as_bytestring().unwrap().into_owned())),
|
|
|
|
|
AtomClass::Symbol => owned(Symbol(v.as_symbol().unwrap().into_owned())),
|
|
|
|
|
AtomClass::Boolean => Box::new(v.as_boolean().unwrap()),
|
|
|
|
|
AtomClass::Float => Box::new(v.as_float().unwrap()),
|
|
|
|
|
AtomClass::Double => Box::new(v.as_double().unwrap()),
|
|
|
|
|
AtomClass::SignedInteger => Box::new(v.as_signed_integer().unwrap()),
|
|
|
|
|
AtomClass::String => Box::new(v.as_string().unwrap().into_owned()),
|
|
|
|
|
AtomClass::ByteString => Box::new(Bytes(v.as_bytestring().unwrap().into_owned())),
|
|
|
|
|
AtomClass::Symbol => Box::new(Symbol(v.as_symbol().unwrap().into_owned())),
|
|
|
|
|
}),
|
|
|
|
|
ValueClass::Compound(c) => Ok(match c {
|
|
|
|
|
CompoundClass::Sequence =>
|
|
|
|
|
owned(v.iter().map(|w| copy_via(w, f)).collect::<Result<Vec<_>, _>>()?),
|
|
|
|
|
Box::new(v.iter().map(|w| copy_via(&*w, f)).collect::<Result<Vec<_>, _>>()?),
|
|
|
|
|
CompoundClass::Set =>
|
|
|
|
|
owned(v.iter().map(|w| copy_via(w, f)).collect::<Result<Set<_>, _>>()?),
|
|
|
|
|
Box::new(v.iter().map(|w| copy_via(&*w, f)).collect::<Result<Set<_>, _>>()?),
|
|
|
|
|
CompoundClass::Record =>
|
|
|
|
|
owned(Record::new(
|
|
|
|
|
copy_via(v.label(), f)?,
|
|
|
|
|
v.iter().map(|w| copy_via(w, f)).collect::<Result<Vec<_>, _>>()?)),
|
|
|
|
|
Box::new(Record::new(
|
|
|
|
|
copy_via(&*v.label(), f)?,
|
|
|
|
|
v.iter().map(|w| copy_via(&*w, f)).collect::<Result<Vec<_>, _>>()?)),
|
|
|
|
|
CompoundClass::Dictionary =>
|
|
|
|
|
owned(v.entries().map(|(k, w)| Ok((copy_via(k, f)?, copy_via(w, f)?)))
|
|
|
|
|
Box::new(v.entries().map(|(k, w)| Ok((copy_via(&*k, f)?, copy_via(&*w, f)?)))
|
|
|
|
|
.collect::<Result<Map<_, _>, _>>()?),
|
|
|
|
|
}),
|
|
|
|
|
ValueClass::Embedded => f(&v.embedded()),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'a, D: Domain + 'static> From<&'a dyn ValueImpl<D>> for PlainValue<'static, D> {
|
|
|
|
|
impl<'a, D: Domain> From<&'a dyn ValueImpl<D>> for PlainValue<'static, D> {
|
|
|
|
|
fn from(v: &'a dyn ValueImpl<D>) -> Self {
|
|
|
|
|
v.value_clone()
|
|
|
|
|
}
|
|
|
|
@ -128,7 +211,7 @@ impl<'a, D: Domain + 'static> From<&'a dyn ValueImpl<D>> for PlainValue<'static,
|
|
|
|
|
|
|
|
|
|
impl<'a, D: Domain, V: ValueImpl<D> + ?Sized> ValueImpl<D> for &'a V {
|
|
|
|
|
fn write(&self, w: &mut dyn Writer, enc: &mut dyn DomainEncode<D>) -> io::Result<()> { (*self).write(w, enc) }
|
|
|
|
|
fn value_clone(&self) -> PlainValue<'static, D> where D: 'static { (*self).value_clone() }
|
|
|
|
|
fn value_clone(&self) -> PlainValue<'static, D> { (*self).value_clone() }
|
|
|
|
|
fn value_class(&self) -> ValueClass { (*self).value_class() }
|
|
|
|
|
fn as_boolean(&self) -> Option<bool> { (*self).as_boolean() }
|
|
|
|
|
fn as_float(&self) -> Option<f32> { (*self).as_float() }
|
|
|
|
@ -139,24 +222,24 @@ impl<'a, D: Domain, V: ValueImpl<D> + ?Sized> ValueImpl<D> for &'a V {
|
|
|
|
|
fn as_bytestring(&self) -> Option<Cow<'_, [u8]>> { (*self).as_bytestring() }
|
|
|
|
|
fn as_symbol(&self) -> Option<Cow<'_, str>> { (*self).as_symbol() }
|
|
|
|
|
fn is_record(&self) -> bool { (*self).is_record() }
|
|
|
|
|
fn label(&self) -> &dyn ValueImpl<D> { (*self).label() }
|
|
|
|
|
fn label(&self) -> Value<'_, D> { (*self).label() }
|
|
|
|
|
fn is_sequence(&self) -> bool { (*self).is_sequence() }
|
|
|
|
|
fn len(&self) -> usize { (*self).len() }
|
|
|
|
|
fn index(&self, i: usize) -> &dyn ValueImpl<D> { (*self).index(i) }
|
|
|
|
|
fn iter(&self) -> Box<dyn Iterator<Item = &dyn ValueImpl<D>> + '_> { (*self).iter() }
|
|
|
|
|
fn index(&self, i: usize) -> Value<'_, D> { (*self).index(i) }
|
|
|
|
|
fn iter(&self) -> Box<dyn Iterator<Item = Value<'_, D>> + '_> { (*self).iter() }
|
|
|
|
|
fn is_set(&self) -> bool { (*self).is_set() }
|
|
|
|
|
fn has(&self, v: &dyn ValueImpl<D>) -> bool { (*self).has(v) }
|
|
|
|
|
fn is_dictionary(&self) -> bool { (*self).is_dictionary() }
|
|
|
|
|
fn get<'value>(&'value self, k: &dyn ValueImpl<D>) -> Option<&'value dyn ValueImpl<D>> { (*self).get(k) }
|
|
|
|
|
fn entries(&self) -> Box<dyn Iterator<Item = (&dyn ValueImpl<D>, &dyn ValueImpl<D>)> + '_> { (*self).entries() }
|
|
|
|
|
fn get(&self, k: &dyn ValueImpl<D>) -> Option<Value<'_, D>> { (*self).get(k) }
|
|
|
|
|
fn entries(&self) -> Box<dyn Iterator<Item = (Value<'_, D>, Value<'_, D>)> + '_> { (*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> ValueImpl<D> for PlainValue<'a, D> {
|
|
|
|
|
impl<'va, D: Domain> ValueImpl<D> for PlainValue<'va, D> {
|
|
|
|
|
fn write(&self, w: &mut dyn Writer, enc: &mut dyn DomainEncode<D>) -> 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_clone(&self) -> PlainValue<'static, D> { self.as_ref().value_clone() }
|
|
|
|
|
fn value_class(&self) -> ValueClass { self.as_ref().value_class() }
|
|
|
|
|
fn as_boolean(&self) -> Option<bool> { self.as_ref().as_boolean() }
|
|
|
|
|
fn as_float(&self) -> Option<f32> { self.as_ref().as_float() }
|
|
|
|
@ -167,16 +250,16 @@ impl<'a, D: Domain> ValueImpl<D> for PlainValue<'a, D> {
|
|
|
|
|
fn as_bytestring(&self) -> Option<Cow<'_, [u8]>> { self.as_ref().as_bytestring() }
|
|
|
|
|
fn as_symbol(&self) -> Option<Cow<'_, str>> { self.as_ref().as_symbol() }
|
|
|
|
|
fn is_record(&self) -> bool { self.as_ref().is_record() }
|
|
|
|
|
fn label(&self) -> &dyn ValueImpl<D> { self.as_ref().label() }
|
|
|
|
|
fn label(&self) -> Value<'_, D> { 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 ValueImpl<D> { self.as_ref().index(i) }
|
|
|
|
|
fn iter(&self) -> Box<dyn Iterator<Item = &dyn ValueImpl<D>> + '_> { self.as_ref().iter() }
|
|
|
|
|
fn index(&self, i: usize) -> Value<'_, D> { self.as_ref().index(i) }
|
|
|
|
|
fn iter(&self) -> Box<dyn Iterator<Item = Value<'_, D>> + '_> { self.as_ref().iter() }
|
|
|
|
|
fn is_set(&self) -> bool { self.as_ref().is_set() }
|
|
|
|
|
fn has(&self, v: &dyn ValueImpl<D>) -> bool { self.as_ref().has(v) }
|
|
|
|
|
fn is_dictionary(&self) -> bool { self.as_ref().is_dictionary() }
|
|
|
|
|
fn get<'value>(&'value self, k: &dyn ValueImpl<D>) -> Option<&'value dyn ValueImpl<D>> { self.as_ref().get(k) }
|
|
|
|
|
fn entries(&self) -> Box<dyn Iterator<Item = (&dyn ValueImpl<D>, &dyn ValueImpl<D>)> + '_> { self.as_ref().entries() }
|
|
|
|
|
fn get(&self, k: &dyn ValueImpl<D>) -> Option<Value<'_, D>> { self.as_ref().get(k) }
|
|
|
|
|
fn entries(&self) -> Box<dyn Iterator<Item = (Value<'_, D>, Value<'_, D>)> + '_> { 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() }
|
|
|
|
@ -188,11 +271,11 @@ impl<'a, D: Domain> Debug for dyn ValueImpl<D> + 'a {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'a, Err: Into<io::Error>, D: Domain + FromStr<Err = Err> + 'static> FromStr for PlainValue<'a, D> {
|
|
|
|
|
impl<Err: Into<io::Error>, D: Domain + FromStr<Err = Err>> FromStr for PlainValue<'static, D> {
|
|
|
|
|
type Err = io::Error;
|
|
|
|
|
|
|
|
|
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
|
|
|
|
crate::annotated_from_str(s, &mut DefaultDomainCodec)
|
|
|
|
|
Ok(crate::annotated_from_str(s, &mut DefaultDomainCodec)?.value_clone())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -233,8 +316,8 @@ impl<'a, D: Domain> Hash for dyn ValueImpl<D> + 'a {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn iters_eq<'a, D: Domain>(
|
|
|
|
|
mut i1: Box<dyn Iterator<Item = &dyn ValueImpl<D>> + 'a>,
|
|
|
|
|
mut i2: Box<dyn Iterator<Item = &dyn ValueImpl<D>> + 'a>,
|
|
|
|
|
mut i1: Box<dyn Iterator<Item = Value<'_, D>> + 'a>,
|
|
|
|
|
mut i2: Box<dyn Iterator<Item = Value<'_, D>> + 'a>,
|
|
|
|
|
) -> bool {
|
|
|
|
|
loop {
|
|
|
|
|
match i1.next() {
|
|
|
|
@ -293,8 +376,8 @@ impl<'a, D: Domain> PartialEq for dyn ValueImpl<D> + 'a {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn iters_cmp<'a, D: Domain>(
|
|
|
|
|
mut i1: Box<dyn Iterator<Item = &dyn ValueImpl<D>> + 'a>,
|
|
|
|
|
mut i2: Box<dyn Iterator<Item = &dyn ValueImpl<D>> + 'a>,
|
|
|
|
|
mut i1: Box<dyn Iterator<Item = Value<'_, D>> + 'a>,
|
|
|
|
|
mut i2: Box<dyn Iterator<Item = Value<'_, D>> + 'a>,
|
|
|
|
|
) -> Ordering {
|
|
|
|
|
loop {
|
|
|
|
|
match i1.next() {
|
|
|
|
@ -304,7 +387,7 @@ fn iters_cmp<'a, D: Domain>(
|
|
|
|
|
}
|
|
|
|
|
Some(v1) => match i2.next() {
|
|
|
|
|
None => return Ordering::Greater,
|
|
|
|
|
Some(v2) => match v1.cmp(v2) {
|
|
|
|
|
Some(v2) => match v1.cmp(&v2) {
|
|
|
|
|
Ordering::Equal => (),
|
|
|
|
|
other => return other,
|
|
|
|
|
}
|
|
|
|
@ -335,7 +418,7 @@ impl<'a, D: Domain> Ord for dyn ValueImpl<D> + 'a {
|
|
|
|
|
},
|
|
|
|
|
ValueClass::Compound(c) => match c {
|
|
|
|
|
CompoundClass::Record =>
|
|
|
|
|
self.label().cmp(other.label()).then_with(
|
|
|
|
|
self.label().cmp(&other.label()).then_with(
|
|
|
|
|
|| iters_cmp(self.iter(), other.iter())),
|
|
|
|
|
CompoundClass::Sequence => iters_cmp(self.iter(), other.iter()),
|
|
|
|
|
CompoundClass::Set => {
|
|
|
|
@ -374,7 +457,7 @@ pub enum Atom<'a> {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'a> Atom<'a> {
|
|
|
|
|
pub fn into_value<D: Domain>(self) -> PlainValue<'static, D> {
|
|
|
|
|
pub fn into_value<'b: 'a, D: Domain>(self) -> PlainValue<'b, D> {
|
|
|
|
|
match self {
|
|
|
|
|
Atom::Boolean(b) => Box::new(b),
|
|
|
|
|
Atom::Float(f) => Box::new(f),
|
|
|
|
@ -414,7 +497,7 @@ impl<'a, D: Domain> ValueImpl<D> for Atom<'a> {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn value_clone(&self) -> PlainValue<'static, D> where D: 'static {
|
|
|
|
|
fn value_clone(&self) -> PlainValue<'static, D> {
|
|
|
|
|
self.clone().into_value()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -470,20 +553,20 @@ impl FromStr for NoValue {
|
|
|
|
|
|
|
|
|
|
impl<D: Domain> ValueImpl<D> for NoValue {
|
|
|
|
|
fn write(&self, _w: &mut dyn Writer, _enc: &mut dyn DomainEncode<D>) -> io::Result<()> { unreachable!() }
|
|
|
|
|
fn value_clone(&self) -> PlainValue<'static, D> where D: 'static { unreachable!() }
|
|
|
|
|
fn value_clone(&self) -> PlainValue<'static, D> { unreachable!() }
|
|
|
|
|
fn value_class(&self) -> ValueClass { unreachable!() }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<D: Domain> ValueImpl<D> for bool {
|
|
|
|
|
fn write(&self, w: &mut dyn Writer, __enc: &mut dyn DomainEncode<D>) -> io::Result<()> { w.write_bool(*self) }
|
|
|
|
|
fn value_clone(&self) -> PlainValue<'static, D> where D: 'static { Box::new(*self) }
|
|
|
|
|
fn value_clone(&self) -> PlainValue<'static, D> { Box::new(*self) }
|
|
|
|
|
fn value_class(&self) -> ValueClass { ValueClass::Atomic(AtomClass::Boolean) }
|
|
|
|
|
fn as_boolean(&self) -> Option<bool> { Some(*self) }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<D: Domain> ValueImpl<D> for u64 {
|
|
|
|
|
fn write(&self, w: &mut dyn Writer, _enc: &mut dyn DomainEncode<D>) -> io::Result<()> { w.write_u64(*self) }
|
|
|
|
|
fn value_clone(&self) -> PlainValue<'static, D> where D: 'static { Box::new(*self) }
|
|
|
|
|
fn value_clone(&self) -> PlainValue<'static, D> { Box::new(*self) }
|
|
|
|
|
fn value_class(&self) -> ValueClass { ValueClass::Atomic(AtomClass::SignedInteger) }
|
|
|
|
|
fn as_signed_integer(&self) -> Option<SignedInteger> {
|
|
|
|
|
Some((*self).into())
|
|
|
|
@ -492,7 +575,7 @@ impl<D: Domain> ValueImpl<D> for u64 {
|
|
|
|
|
|
|
|
|
|
impl<D: Domain> ValueImpl<D> for SignedInteger {
|
|
|
|
|
fn write(&self, w: &mut dyn Writer, _enc: &mut dyn DomainEncode<D>) -> io::Result<()> { w.write_signed_integer(self) }
|
|
|
|
|
fn value_clone(&self) -> PlainValue<'static, D> where D: 'static { Box::new(self.clone()) }
|
|
|
|
|
fn value_clone(&self) -> PlainValue<'static, D> { Box::new(self.clone()) }
|
|
|
|
|
fn value_class(&self) -> ValueClass { ValueClass::Atomic(AtomClass::SignedInteger) }
|
|
|
|
|
fn as_signed_integer(&self) -> Option<SignedInteger> {
|
|
|
|
|
Some(self.clone())
|
|
|
|
@ -501,7 +584,7 @@ impl<D: Domain> ValueImpl<D> for SignedInteger {
|
|
|
|
|
|
|
|
|
|
impl<D: Domain> ValueImpl<D> for f32 {
|
|
|
|
|
fn write(&self, w: &mut dyn Writer, _enc: &mut dyn DomainEncode<D>) -> io::Result<()> { w.write_f32(*self) }
|
|
|
|
|
fn value_clone(&self) -> PlainValue<'static, D> where D: 'static { Box::new(*self) }
|
|
|
|
|
fn value_clone(&self) -> PlainValue<'static, D> { Box::new(*self) }
|
|
|
|
|
fn value_class(&self) -> ValueClass { ValueClass::Atomic(AtomClass::Float) }
|
|
|
|
|
fn as_float(&self) -> Option<f32> { Some(*self) }
|
|
|
|
|
fn as_double(&self) -> Option<f64> { Some(*self as f64) }
|
|
|
|
@ -509,7 +592,7 @@ impl<D: Domain> ValueImpl<D> for f32 {
|
|
|
|
|
|
|
|
|
|
impl<D: Domain> ValueImpl<D> for f64 {
|
|
|
|
|
fn write(&self, w: &mut dyn Writer, _enc: &mut dyn DomainEncode<D>) -> io::Result<()> { w.write_f64(*self) }
|
|
|
|
|
fn value_clone(&self) -> PlainValue<'static, D> where D: 'static { Box::new(*self) }
|
|
|
|
|
fn value_clone(&self) -> PlainValue<'static, D> { Box::new(*self) }
|
|
|
|
|
fn value_class(&self) -> ValueClass { ValueClass::Atomic(AtomClass::Float) }
|
|
|
|
|
fn as_float(&self) -> Option<f32> { Some(*self as f32) }
|
|
|
|
|
fn as_double(&self) -> Option<f64> { Some(*self) }
|
|
|
|
@ -517,14 +600,14 @@ impl<D: Domain> ValueImpl<D> for f64 {
|
|
|
|
|
|
|
|
|
|
impl<D: Domain> ValueImpl<D> for str {
|
|
|
|
|
fn write(&self, w: &mut dyn Writer, _enc: &mut dyn DomainEncode<D>) -> io::Result<()> { w.write_string(self) }
|
|
|
|
|
fn value_clone(&self) -> PlainValue<'static, D> where D: 'static { Box::new(self.to_owned()) }
|
|
|
|
|
fn value_clone(&self) -> PlainValue<'static, D> { Box::new(self.to_owned()) }
|
|
|
|
|
fn value_class(&self) -> ValueClass { ValueClass::Atomic(AtomClass::String) }
|
|
|
|
|
fn as_string(&self) -> Option<Cow<'_, str>> { Some(Cow::Borrowed(self)) }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<D: Domain> ValueImpl<D> for String {
|
|
|
|
|
fn write(&self, w: &mut dyn Writer, _enc: &mut dyn DomainEncode<D>) -> io::Result<()> { w.write_string(self) }
|
|
|
|
|
fn value_clone(&self) -> PlainValue<'static, D> where D: 'static { Box::new(self.clone()) }
|
|
|
|
|
fn value_clone(&self) -> PlainValue<'static, D> { Box::new(self.clone()) }
|
|
|
|
|
fn value_class(&self) -> ValueClass { ValueClass::Atomic(AtomClass::String) }
|
|
|
|
|
fn as_string(&self) -> Option<Cow<'_, str>> { Some(Cow::Borrowed(self)) }
|
|
|
|
|
}
|
|
|
|
@ -541,7 +624,7 @@ impl<T: AsRef<[u8]> + Debug> Bytes<T> {
|
|
|
|
|
|
|
|
|
|
impl<T: AsRef<[u8]> + Debug, D: Domain> ValueImpl<D> for Bytes<T> {
|
|
|
|
|
fn write(&self, w: &mut dyn Writer, _enc: &mut dyn DomainEncode<D>) -> 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_clone(&self) -> PlainValue<'static, D> { Box::new(Bytes(self.0.as_ref().to_owned())) }
|
|
|
|
|
fn value_class(&self) -> ValueClass { ValueClass::Atomic(AtomClass::ByteString) }
|
|
|
|
|
fn as_bytestring(&self) -> Option<Cow<'_, [u8]>> { Some(Cow::Borrowed(self.0.as_ref())) }
|
|
|
|
|
}
|
|
|
|
@ -558,7 +641,7 @@ impl<T: AsRef<str> + Debug> Symbol<T> {
|
|
|
|
|
|
|
|
|
|
impl<T: AsRef<str> + Debug, D: Domain> ValueImpl<D> for Symbol<T> {
|
|
|
|
|
fn write(&self, w: &mut dyn Writer, _enc: &mut dyn DomainEncode<D>) -> 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_clone(&self) -> PlainValue<'static, D> { Box::new(Symbol(self.0.as_ref().to_owned())) }
|
|
|
|
|
fn value_class(&self) -> ValueClass { ValueClass::Atomic(AtomClass::Symbol) }
|
|
|
|
|
fn as_symbol(&self) -> Option<Cow<'_, str>> { Some(Cow::Borrowed(self.0.as_ref())) }
|
|
|
|
|
}
|
|
|
|
@ -599,16 +682,16 @@ impl<D: Domain, V: ValueImpl<D>> ValueImpl<D> for Record<V> {
|
|
|
|
|
w.end_record()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn value_clone(&self) -> PlainValue<'static, D> where D: 'static {
|
|
|
|
|
fn value_clone(&self) -> PlainValue<'static, D> {
|
|
|
|
|
Box::new(Record(self.0.iter().map(|v| v.value_clone()).collect()))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn value_class(&self) -> ValueClass { ValueClass::Compound(CompoundClass::Record) }
|
|
|
|
|
fn is_record(&self) -> bool { true }
|
|
|
|
|
fn label(&self) -> &dyn ValueImpl<D> { &self.0[0] }
|
|
|
|
|
fn label(&self) -> Value<'_, D> { Value::Borrowed(&self.0[0]) }
|
|
|
|
|
fn len(&self) -> usize { self.0.len() - 1 }
|
|
|
|
|
fn index(&self, i: usize) -> &dyn ValueImpl<D> { &self.0[i + 1] }
|
|
|
|
|
fn iter(&self) -> Box<dyn Iterator<Item = &dyn ValueImpl<D>> + '_> {
|
|
|
|
|
fn index(&self, i: usize) -> Value<'_, D> { Value::Borrowed(&self.0[i + 1]) }
|
|
|
|
|
fn iter(&self) -> Box<dyn Iterator<Item = Value<'_, D>> + '_> {
|
|
|
|
|
Box::new(self.0[1..].iter().map(value))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -618,15 +701,15 @@ impl<D: Domain, V: ValueImpl<D>> ValueImpl<D> for Vec<V> {
|
|
|
|
|
(&self[..]).write(w, enc)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn value_clone(&self) -> PlainValue<'static, D> where D: 'static {
|
|
|
|
|
fn value_clone(&self) -> PlainValue<'static, D> {
|
|
|
|
|
(&self[..]).value_clone()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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 ValueImpl<D> { &self[i] }
|
|
|
|
|
fn iter(&self) -> Box<dyn Iterator<Item = &dyn ValueImpl<D>> + '_> {
|
|
|
|
|
fn index(&self, i: usize) -> Value<'_, D> { Value::Borrowed(&self[i]) }
|
|
|
|
|
fn iter(&self) -> Box<dyn Iterator<Item = Value<'_, D>> + '_> {
|
|
|
|
|
Box::new(self[..].iter().map(value))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -645,20 +728,20 @@ impl<D: Domain, V: ValueImpl<D>> ValueImpl<D> for [V] {
|
|
|
|
|
w.end_sequence()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn value_clone(&self) -> PlainValue<'static, D> where D: 'static {
|
|
|
|
|
fn value_clone(&self) -> PlainValue<'static, D> {
|
|
|
|
|
Box::new(self.iter().map(|v| v.value_clone()).collect::<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 ValueImpl<D> { &self[i] }
|
|
|
|
|
fn iter(&self) -> Box<dyn Iterator<Item = &dyn ValueImpl<D>> + '_> {
|
|
|
|
|
fn index(&self, i: usize) -> Value<'_, D> { Value::Borrowed(&self[i]) }
|
|
|
|
|
fn iter(&self) -> Box<dyn Iterator<Item = Value<'_, D>> + '_> {
|
|
|
|
|
Box::new(self[..].iter().map(value))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'e, D: Domain, E: for<'a> Borrow<Key<'a, D>> + Ord + 'e> ValueImpl<D> for Set<E> {
|
|
|
|
|
impl<D: Domain, E: for<'a> Borrow<Key<'a, D>> + Ord + 'static> ValueImpl<D> for Set<E> {
|
|
|
|
|
fn write(&self, w: &mut dyn Writer, enc: &mut dyn DomainEncode<D>) -> io::Result<()> {
|
|
|
|
|
w.start_set()?;
|
|
|
|
|
let mut b = B::Type::default();
|
|
|
|
@ -672,7 +755,7 @@ impl<'e, D: Domain, E: for<'a> Borrow<Key<'a, D>> + Ord + 'e> ValueImpl<D> for S
|
|
|
|
|
w.end_set()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn value_clone(&self) -> PlainValue<'static, D> where D: 'static {
|
|
|
|
|
fn value_clone(&self) -> PlainValue<'static, D> {
|
|
|
|
|
Box::new(self.iter().map(|v| Key::peel_ref(&v.borrow()).value_clone()).collect::<Set<_>>())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -680,8 +763,8 @@ impl<'e, D: Domain, E: for<'a> Borrow<Key<'a, D>> + Ord + 'e> ValueImpl<D> for S
|
|
|
|
|
fn is_set(&self) -> bool { true }
|
|
|
|
|
fn len(&self) -> usize { self.len() }
|
|
|
|
|
fn has(&self, v: &dyn ValueImpl<D>) -> bool { self.contains(&Key::wrap_ref(v)) }
|
|
|
|
|
fn iter(&self) -> Box<dyn Iterator<Item = &dyn ValueImpl<D>> + '_> {
|
|
|
|
|
Box::new(self.iter().map(|e| Key::peel_ref(&e.borrow())))
|
|
|
|
|
fn iter(&self) -> Box<dyn Iterator<Item = Value<'_, D>> + '_> {
|
|
|
|
|
Box::new(self.iter().map(|e| Value::Borrowed(Key::peel_ref(&e.borrow()))))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -706,7 +789,7 @@ impl<'a, 'b: 'a, D: Domain> Borrow<Key<'a, D>> for &'b (dyn ValueImpl<D> + 'b) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'k, D: Domain, V: ValueImpl<D>, K: for<'a> Borrow<Key<'a, D>> + Ord + 'k> ValueImpl<D>
|
|
|
|
|
impl<D: Domain, V: ValueImpl<D> + 'static, K: for<'a> Borrow<Key<'a, D>> + Ord + 'static> ValueImpl<D>
|
|
|
|
|
for Map<K, V>
|
|
|
|
|
{
|
|
|
|
|
fn write(&self, w: &mut dyn Writer, enc: &mut dyn DomainEncode<D>) -> io::Result<()> {
|
|
|
|
@ -725,7 +808,7 @@ impl<'k, D: Domain, V: ValueImpl<D>, K: for<'a> Borrow<Key<'a, D>> + Ord + 'k> V
|
|
|
|
|
w.end_dictionary()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn value_clone(&self) -> PlainValue<'static, D> where D: 'static {
|
|
|
|
|
fn value_clone(&self) -> PlainValue<'static, D> {
|
|
|
|
|
Box::new(ValueImpl::entries(self).map(|(k, v)| (k.value_clone(), v.value_clone())).collect::<Map<_, _>>())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -733,14 +816,15 @@ impl<'k, D: Domain, V: ValueImpl<D>, K: for<'a> Borrow<Key<'a, D>> + Ord + 'k> V
|
|
|
|
|
fn is_dictionary(&self) -> bool { true }
|
|
|
|
|
fn len(&self) -> usize { self.len() }
|
|
|
|
|
fn has(&self, v: &dyn ValueImpl<D>) -> bool { self.contains_key(&Key::wrap_ref(v)) }
|
|
|
|
|
fn get(&self, k: &dyn ValueImpl<D>) -> Option<&dyn ValueImpl<D>> {
|
|
|
|
|
fn get(&self, k: &dyn ValueImpl<D>) -> Option<Value<'_, D>> {
|
|
|
|
|
match Map::get(self, &Key::wrap_ref(k)) {
|
|
|
|
|
Some(v) => Some(v),
|
|
|
|
|
Some(v) => Some(Value::Borrowed(v)),
|
|
|
|
|
None => None,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fn entries(&self) -> Box<dyn Iterator<Item = (&dyn ValueImpl<D>, &dyn ValueImpl<D>)> + '_> {
|
|
|
|
|
Box::new(self.iter().map(|(k,v)| (Key::peel_ref(&k.borrow()), value(v))))
|
|
|
|
|
fn entries(&self) -> Box<dyn Iterator<Item = (Value<'_, D>, Value<'_, D>)> + '_> {
|
|
|
|
|
Box::new(self.iter().map(
|
|
|
|
|
|(k,v)| (Value::Borrowed(Key::peel_ref(&k.borrow())), value(v))))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -769,14 +853,14 @@ impl<D: Domain> ValueImpl<D> for Embedded<D> {
|
|
|
|
|
w.end_embedded()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn value_clone(&self) -> PlainValue<'static, D> where D: 'static { Box::new(self.clone()) }
|
|
|
|
|
fn value_clone(&self) -> PlainValue<'static, D> { Box::new(self.clone()) }
|
|
|
|
|
fn value_class(&self) -> ValueClass { ValueClass::Embedded }
|
|
|
|
|
fn is_embedded(&self) -> bool { true }
|
|
|
|
|
fn embedded(&self) -> Cow<'_, D> { Cow::Borrowed(&self.0) }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
|
pub struct Annotations<D: Domain, V: ValueImpl<D>>(V, Vec<IOValue>, PhantomData<D>);
|
|
|
|
|
pub struct Annotations<D: Domain, V: ValueImpl<D> + 'static>(V, Vec<IOValue>, PhantomData<D>);
|
|
|
|
|
|
|
|
|
|
impl<D: Domain, V: ValueImpl<D>> Annotations<D, V> {
|
|
|
|
|
pub fn new(value: V, anns: Vec<IOValue>) -> Self {
|
|
|
|
@ -809,7 +893,7 @@ impl<D: Domain, V: ValueImpl<D>> ValueImpl<D> for Annotations<D, V> {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn value_clone(&self) -> PlainValue<'static, D> where D: 'static {
|
|
|
|
|
fn value_clone(&self) -> PlainValue<'static, D> {
|
|
|
|
|
Box::new(Annotations(self.0.value_clone(),
|
|
|
|
|
self.1.iter().map(|v| v.value_clone().into()).collect(),
|
|
|
|
|
PhantomData))
|
|
|
|
@ -825,16 +909,16 @@ impl<D: Domain, V: ValueImpl<D>> ValueImpl<D> for Annotations<D, V> {
|
|
|
|
|
fn as_bytestring(&self) -> Option<Cow<'_, [u8]>> { self.value().as_bytestring() }
|
|
|
|
|
fn as_symbol(&self) -> Option<Cow<'_, str>> { self.value().as_symbol() }
|
|
|
|
|
fn is_record(&self) -> bool { self.value().is_record() }
|
|
|
|
|
fn label(&self) -> &dyn ValueImpl<D> { self.value().label() }
|
|
|
|
|
fn label(&self) -> Value<'_, D> { 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 ValueImpl<D> { self.value().index(i) }
|
|
|
|
|
fn iter(&self) -> Box<dyn Iterator<Item = &dyn ValueImpl<D>> + '_> { self.value().iter() }
|
|
|
|
|
fn index(&self, i: usize) -> Value<'_, D> { self.value().index(i) }
|
|
|
|
|
fn iter(&self) -> Box<dyn Iterator<Item = Value<'_, D>> + '_> { self.value().iter() }
|
|
|
|
|
fn is_set(&self) -> bool { self.value().is_set() }
|
|
|
|
|
fn has(&self, v: &dyn ValueImpl<D>) -> bool { self.value().has(v) }
|
|
|
|
|
fn is_dictionary(&self) -> bool { self.value().is_dictionary() }
|
|
|
|
|
fn get(&self, k: &dyn ValueImpl<D>) -> Option<&dyn ValueImpl<D>> { self.value().get(k) }
|
|
|
|
|
fn entries(&self) -> Box<dyn Iterator<Item = (&dyn ValueImpl<D>, &dyn ValueImpl<D>)> + '_> { self.value().entries() }
|
|
|
|
|
fn get(&self, k: &dyn ValueImpl<D>) -> Option<Value<'_, D>> { self.value().get(k) }
|
|
|
|
|
fn entries(&self) -> Box<dyn Iterator<Item = (Value<'_, D>, Value<'_, D>)> + '_> { 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) }
|
|
|
|
@ -868,7 +952,7 @@ impl<D: Domain, V: ValueImpl<D>> Ord for Annotations<D, V> {
|
|
|
|
|
|
|
|
|
|
#[derive(Clone, Eq, Hash, PartialOrd, Ord)]
|
|
|
|
|
#[repr(transparent)]
|
|
|
|
|
pub struct ArcValue<D: Domain + 'static = IOValue>(Arc<dyn ValueImpl<D>>);
|
|
|
|
|
pub struct ArcValue<D: Domain = IOValue>(Arc<dyn ValueImpl<D>>);
|
|
|
|
|
|
|
|
|
|
#[derive(Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
|
|
|
|
#[repr(transparent)]
|
|
|
|
@ -892,11 +976,11 @@ impl<D: Domain> PartialEq for ArcValue<D> {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<Err: Into<io::Error>, D: Domain + FromStr<Err = Err> + 'static> FromStr for ArcValue<D> {
|
|
|
|
|
impl<Err: Into<io::Error>, D: Domain + FromStr<Err = Err>> FromStr for ArcValue<D> {
|
|
|
|
|
type Err = io::Error;
|
|
|
|
|
|
|
|
|
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
|
|
|
|
Ok(arcvalue(crate::annotated_from_str(s, &mut DefaultDomainCodec)?))
|
|
|
|
|
Ok(arcvalue(crate::annotated_from_str(s, &mut DefaultDomainCodec)?.value_clone()))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -951,16 +1035,16 @@ impl<D: Domain> ValueImpl<D> for ArcValue<D> {
|
|
|
|
|
fn as_bytestring(&self) -> Option<Cow<'_, [u8]>> { self.0.as_bytestring() }
|
|
|
|
|
fn as_symbol(&self) -> Option<Cow<'_, str>> { self.0.as_symbol() }
|
|
|
|
|
fn is_record(&self) -> bool { self.0.is_record() }
|
|
|
|
|
fn label(&self) -> &dyn ValueImpl<D> { self.0.label() }
|
|
|
|
|
fn label(&self) -> Value<'_, D> { 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 ValueImpl<D> { self.0.index(i) }
|
|
|
|
|
fn iter(&self) -> Box<dyn Iterator<Item = &dyn ValueImpl<D>> + '_> { self.0.iter() }
|
|
|
|
|
fn index(&self, i: usize) -> Value<'_, D> { self.0.index(i) }
|
|
|
|
|
fn iter(&self) -> Box<dyn Iterator<Item = Value<'_, D>> + '_> { self.0.iter() }
|
|
|
|
|
fn is_set(&self) -> bool { self.0.is_set() }
|
|
|
|
|
fn has(&self, v: &dyn ValueImpl<D>) -> bool { self.0.has(v) }
|
|
|
|
|
fn is_dictionary(&self) -> bool { self.0.is_dictionary() }
|
|
|
|
|
fn get<'value>(&'value self, k: &dyn ValueImpl<D>) -> Option<&'value dyn ValueImpl<D>> { self.0.get(k) }
|
|
|
|
|
fn entries(&self) -> Box<dyn Iterator<Item = (&dyn ValueImpl<D>, &dyn ValueImpl<D>)> + '_> { self.0.entries() }
|
|
|
|
|
fn get(&self, k: &dyn ValueImpl<D>) -> Option<Value<'_, D>> { self.0.get(k) }
|
|
|
|
|
fn entries(&self) -> Box<dyn Iterator<Item = (Value<'_, D>, Value<'_, D>)> + '_> { 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() }
|
|
|
|
@ -979,16 +1063,16 @@ impl ValueImpl<IOValue> for IOValue {
|
|
|
|
|
fn as_bytestring(&self) -> Option<Cow<'_, [u8]>> { self.0.as_bytestring() }
|
|
|
|
|
fn as_symbol(&self) -> Option<Cow<'_, str>> { self.0.as_symbol() }
|
|
|
|
|
fn is_record(&self) -> bool { self.0.is_record() }
|
|
|
|
|
fn label(&self) -> &dyn ValueImpl<IOValue> { self.0.label() }
|
|
|
|
|
fn label(&self) -> Value<'_, IOValue> { 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 ValueImpl<IOValue> { self.0.index(i) }
|
|
|
|
|
fn iter(&self) -> Box<dyn Iterator<Item = &dyn ValueImpl<IOValue>> + '_> { self.0.iter() }
|
|
|
|
|
fn index(&self, i: usize) -> Value<'_, IOValue> { self.0.index(i) }
|
|
|
|
|
fn iter(&self) -> Box<dyn Iterator<Item = Value<'_, IOValue>> + '_> { self.0.iter() }
|
|
|
|
|
fn is_set(&self) -> bool { self.0.is_set() }
|
|
|
|
|
fn has(&self, v: &dyn ValueImpl<IOValue>) -> bool { self.0.has(v) }
|
|
|
|
|
fn is_dictionary(&self) -> bool { self.0.is_dictionary() }
|
|
|
|
|
fn get<'value>(&'value self, k: &dyn ValueImpl<IOValue>) -> Option<&'value dyn ValueImpl<IOValue>> { self.0.get(k) }
|
|
|
|
|
fn entries(&self) -> Box<dyn Iterator<Item = (&dyn ValueImpl<IOValue>, &dyn ValueImpl<IOValue>)> + '_> { self.0.entries() }
|
|
|
|
|
fn get(&self, k: &dyn ValueImpl<IOValue>) -> Option<Value<'_, IOValue>> { self.0.get(k) }
|
|
|
|
|
fn entries(&self) -> Box<dyn Iterator<Item = (Value<'_, IOValue>, Value<'_, IOValue>)> + '_> { 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() }
|
|
|
|
|