More pushing the boulder uphill

This commit is contained in:
Tony Garnock-Jones 2022-11-17 10:25:16 +01:00
parent a3f598436b
commit eeb50fcf65
1 changed files with 67 additions and 67 deletions

View File

@ -30,7 +30,7 @@ pub struct Value<V: ValueImpl>(pub V);
/// Atomic values from the specification.
pub trait ValueImpl: Sized {
type Embedded: Domain;
type Mapped<E: Domain>: ValueImpl;
type Mapped<E: Domain>: ValueImpl<Embedded = E>;
type Items<'a>: Iterator<Item = &'a Value<Self>> + 'a where Self: 'a;
type Entries<'a>: Iterator<Item = (&'a Value<Self>, &'a Value<Self>)> + 'a where Self: 'a;
@ -314,79 +314,79 @@ impl<'a> From<String> for Atom<'a> { fn from(v: String) -> Self { Atom::String(C
impl<'a> From<&'a [u8]> for Atom<'a> { fn from(v: &'a [u8]) -> Self { Atom::ByteString(Cow::Borrowed(v)) } }
impl<'a> From<Vec<u8>> for Atom<'a> { fn from(v: Vec<u8>) -> Self { Atom::ByteString(Cow::Owned(v)) } }
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub enum NoValue {}
// #[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
// pub enum NoValue {}
impl Domain for NoValue {
type Decode = NoEmbeddedDomainCodec;
type Encode = NoEmbeddedDomainCodec;
}
// impl Domain for NoValue {
// type Decode = NoEmbeddedDomainCodec;
// type Encode = NoEmbeddedDomainCodec;
// }
impl FromStr for NoValue {
type Err = io::Error;
// impl FromStr for NoValue {
// type Err = io::Error;
fn from_str(_s: &str) -> Result<Self, Self::Err> {
Err(io::Error::new(io::ErrorKind::Unsupported, "Embedded values not supported here"))
}
}
// fn from_str(_s: &str) -> Result<Self, Self::Err> {
// Err(io::Error::new(io::ErrorKind::Unsupported, "Embedded values not supported here"))
// }
// }
pub struct NoIterator<A> {
nothing: NoValue,
phantom: PhantomData<A>,
}
// pub struct NoIterator<A> {
// nothing: NoValue,
// phantom: PhantomData<A>,
// }
impl<A> Iterator for NoIterator<A> {
type Item = A;
// impl<A> Iterator for NoIterator<A> {
// type Item = A;
fn next(&mut self) -> Option<Self::Item> {
None
}
}
// fn next(&mut self) -> Option<Self::Item> {
// None
// }
// }
impl ValueImpl for NoValue {
type Embedded = NoValue;
type Mapped<_E: Domain> = NoValue;
type Items<'a> = NoIterator<&'a Value<Self>>;
type Entries<'a> = NoIterator<(&'a Value<Self>, &'a Value<Self>)>;
// impl ValueImpl for NoValue {
// type Embedded = NoValue;
// type Mapped<_E: Domain> = NoValue;
// type Items<'a> = NoIterator<&'a Value<Self>>;
// type Entries<'a> = NoIterator<(&'a Value<Self>, &'a Value<Self>)>;
fn write(&self, _w: &mut dyn Writer, _enc: &mut dyn DomainEncode<Self::Embedded>) -> io::Result<()> { unreachable!() }
fn value_class(&self) -> ValueClass { unreachable!() }
fn as_boolean(&self) -> Option<bool> { unreachable!() }
fn as_float(&self) -> Option<f32> { unreachable!() }
fn as_double(&self) -> Option<f64> { unreachable!() }
fn as_signed_integer(&self) -> Option<Cow<'_, SignedInteger>> { unreachable!() }
fn as_string(&self) -> Option<Cow<'_, str>> { unreachable!() }
fn as_bytestring(&self) -> Option<Cow<'_, [u8]>> { unreachable!() }
fn as_symbol(&self) -> Option<Cow<'_, str>> { unreachable!() }
fn is_record(&self) -> bool { unreachable!() }
fn label(&self) -> Value<Self> { unreachable!() }
fn is_sequence(&self) -> bool { unreachable!() }
fn len(&self) -> usize { unreachable!() }
fn index(&self, _i: usize) -> Value<Self> { unreachable!() }
fn iter(&self) -> Self::Items<'_> { unreachable!() }
fn is_set(&self) -> bool { unreachable!() }
fn has<E: ValueImpl<Embedded = Self::Embedded>>(&self, _v: &Value<E>) -> bool { unreachable!() }
fn is_dictionary(&self) -> bool { unreachable!() }
fn get<K: ValueImpl<Embedded = Self::Embedded>>(&self, _k: &Value<K>) -> Option<Value<Self>> { unreachable!() }
fn entries(&self) -> Self::Entries<'_> { unreachable!() }
fn as_embedded(&self) -> Option<Cow<'_, Self::Embedded>> { unreachable!() }
fn annotations(&self) -> Option<Cow<'_, [IOValue]>> { unreachable!() }
fn peeled(&self) -> &Self { unreachable!() }
// fn write(&self, _w: &mut dyn Writer, _enc: &mut dyn DomainEncode<Self::Embedded>) -> io::Result<()> { unreachable!() }
// fn value_class(&self) -> ValueClass { unreachable!() }
// fn as_boolean(&self) -> Option<bool> { unreachable!() }
// fn as_float(&self) -> Option<f32> { unreachable!() }
// fn as_double(&self) -> Option<f64> { unreachable!() }
// fn as_signed_integer(&self) -> Option<Cow<'_, SignedInteger>> { unreachable!() }
// fn as_string(&self) -> Option<Cow<'_, str>> { unreachable!() }
// fn as_bytestring(&self) -> Option<Cow<'_, [u8]>> { unreachable!() }
// fn as_symbol(&self) -> Option<Cow<'_, str>> { unreachable!() }
// fn is_record(&self) -> bool { unreachable!() }
// fn label(&self) -> Value<Self> { unreachable!() }
// fn is_sequence(&self) -> bool { unreachable!() }
// fn len(&self) -> usize { unreachable!() }
// fn index(&self, _i: usize) -> Value<Self> { unreachable!() }
// fn iter(&self) -> Self::Items<'_> { unreachable!() }
// fn is_set(&self) -> bool { unreachable!() }
// fn has<E: ValueImpl<Embedded = Self::Embedded>>(&self, _v: &Value<E>) -> bool { unreachable!() }
// fn is_dictionary(&self) -> bool { unreachable!() }
// fn get<K: ValueImpl<Embedded = Self::Embedded>>(&self, _k: &Value<K>) -> Option<Value<Self>> { unreachable!() }
// fn entries(&self) -> Self::Entries<'_> { unreachable!() }
// fn as_embedded(&self) -> Option<Cow<'_, Self::Embedded>> { unreachable!() }
// fn annotations(&self) -> Option<Cow<'_, [IOValue]>> { unreachable!() }
// fn peeled(&self) -> &Self { unreachable!() }
fn copy<E: ValueImpl, F, Err>(w: &Value<E>, f: &mut F) -> Result<Value<Self>, Err>
where
F: FnMut(&E::Embedded) -> Result<Value<Self>, Err>
{
panic!("Cannot copy into NoValue")
}
// fn copy<E: ValueImpl, F, Err>(w: &Value<E>, f: &mut F) -> Result<Value<Self>, Err>
// where
// F: FnMut(&E::Embedded) -> Result<Value<Self>, Err>
// {
// panic!("Cannot copy into NoValue")
// }
fn map_embedded<E: Domain, F, Err>(&self, f: &mut F) -> Result<Value<Self::Mapped<E>>, Err>
where
F: FnMut(&Self::Embedded) -> Result<E, Err>
{
unreachable!()
}
}
// fn map_embedded<E: Domain, F, Err>(&self, f: &mut F) -> Result<Value<Self::Mapped<E>>, Err>
// where
// F: FnMut(&Self::Embedded) -> Result<E, Err>
// {
// unreachable!()
// }
// }
pub enum Shell<'a, V: ValueImpl> {
Atom(Atom<'a>),
@ -459,10 +459,10 @@ impl<'a, V: ValueImpl> ValueImpl for Shell<'a, V> {
w.end_embedded()
}
Shell::Annotated(b) => {
let (value, anns) = b.as_ref();
let (value, anns) = b.0.as_ref();
w.start_annotations()?;
let mut b = B::Type::default();
for ann in &anns {
for ann in anns {
b.shift(Some(B::Item::Annotation));
w.boundary(&b)?;
ann.write(w, &mut IOValueDomainCodec)?;
@ -529,7 +529,7 @@ impl<'a, V: ValueImpl> ValueImpl for Shell<'a, V> {
where
F: FnMut(&V::Embedded) -> Result<E, Err>
{
Self::copy(self, &mut |d| Ok(Self::Embedded(f(d)?)))
Self::Mapped::<E>::copy(&Value(*self), &mut |d| Ok(Value(Self::Mapped::<E>::Embedded(f(d)?))))
}
fn as_boolean(&self) -> Option<bool> {