forked from syndicate-lang/preserves
Make it so that any defined language can be used as placeholder to identity-(un)parse `NestedValue`s
This commit is contained in:
parent
9936ddb29d
commit
b1ed29657e
|
@ -64,6 +64,9 @@ macro_rules! define_language {
|
||||||
}
|
}
|
||||||
})*
|
})*
|
||||||
|
|
||||||
|
impl<N: $crate::support::preserves::value::NestedValue> $crate::support::NestedValueCodec
|
||||||
|
for $lang<N> {}
|
||||||
|
|
||||||
mod $fname {
|
mod $fname {
|
||||||
use super::*;
|
use super::*;
|
||||||
lazy_static::lazy_static! {
|
lazy_static::lazy_static! {
|
||||||
|
|
|
@ -19,12 +19,15 @@ use std::sync::Arc;
|
||||||
|
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
|
pub trait NestedValueCodec {} // marker trait
|
||||||
|
impl NestedValueCodec for () {}
|
||||||
|
|
||||||
pub trait Parse<L, Value: NestedValue>: Sized {
|
pub trait Parse<L, Value: NestedValue>: Sized {
|
||||||
fn parse(language: L, value: &Value) -> Result<Self, ParseError>;
|
fn parse(language: L, value: &Value) -> Result<Self, ParseError>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Value: NestedValue> Parse<&'a (), Value> for Value {
|
impl<'a, T: NestedValueCodec, Value: NestedValue> Parse<&'a T, Value> for Value {
|
||||||
fn parse(_language: &'a (), value: &Value) -> Result<Self, ParseError> {
|
fn parse(_language: &'a T, value: &Value) -> Result<Self, ParseError> {
|
||||||
Ok(value.clone())
|
Ok(value.clone())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,8 +36,8 @@ pub trait Unparse<L, Value: NestedValue> {
|
||||||
fn unparse(&self, language: L) -> Value;
|
fn unparse(&self, language: L) -> Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Value: NestedValue> Unparse<&'a (), Value> for Value {
|
impl<'a, T: NestedValueCodec, Value: NestedValue> Unparse<&'a T, Value> for Value {
|
||||||
fn unparse(&self, _language: &'a ()) -> Value {
|
fn unparse(&self, _language: &'a T) -> Value {
|
||||||
self.clone()
|
self.clone()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue