diff --git a/implementations/rust/preserves-schema/src/lib.rs b/implementations/rust/preserves-schema/src/lib.rs index ec34461..39be38c 100644 --- a/implementations/rust/preserves-schema/src/lib.rs +++ b/implementations/rust/preserves-schema/src/lib.rs @@ -64,6 +64,9 @@ macro_rules! define_language { } })* + impl $crate::support::NestedValueCodec + for $lang {} + mod $fname { use super::*; lazy_static::lazy_static! { diff --git a/implementations/rust/preserves-schema/src/support/mod.rs b/implementations/rust/preserves-schema/src/support/mod.rs index e159574..e656671 100644 --- a/implementations/rust/preserves-schema/src/support/mod.rs +++ b/implementations/rust/preserves-schema/src/support/mod.rs @@ -19,12 +19,15 @@ use std::sync::Arc; use thiserror::Error; +pub trait NestedValueCodec {} // marker trait +impl NestedValueCodec for () {} + pub trait Parse: Sized { fn parse(language: L, value: &Value) -> Result; } -impl<'a, Value: NestedValue> Parse<&'a (), Value> for Value { - fn parse(_language: &'a (), value: &Value) -> Result { +impl<'a, T: NestedValueCodec, Value: NestedValue> Parse<&'a T, Value> for Value { + fn parse(_language: &'a T, value: &Value) -> Result { Ok(value.clone()) } } @@ -33,8 +36,8 @@ pub trait Unparse { fn unparse(&self, language: L) -> Value; } -impl<'a, Value: NestedValue> Unparse<&'a (), Value> for Value { - fn unparse(&self, _language: &'a ()) -> Value { +impl<'a, T: NestedValueCodec, Value: NestedValue> Unparse<&'a T, Value> for Value { + fn unparse(&self, _language: &'a T) -> Value { self.clone() } }