From 3b728aff86a086f71f013b77a715c33748d9f6a8 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Wed, 28 Oct 2020 21:45:42 +0000 Subject: Make type annotation optional to allow serializing SimpleValue --- serde_dhall/src/options/ser.rs | 33 ++++++++------------------------- 1 file changed, 8 insertions(+), 25 deletions(-) (limited to 'serde_dhall/src/options/ser.rs') diff --git a/serde_dhall/src/options/ser.rs b/serde_dhall/src/options/ser.rs index 026dd21..ea5d16a 100644 --- a/serde_dhall/src/options/ser.rs +++ b/serde_dhall/src/options/ser.rs @@ -1,25 +1,5 @@ -use crate::{Result, SimpleType, StaticType, ToDhall}; - -#[derive(Debug, Clone, Copy)] -pub struct NoAnnot; -#[derive(Debug, Clone, Copy)] -pub struct ManualAnnot<'ty>(&'ty SimpleType); -#[derive(Debug, Clone, Copy)] -pub struct StaticAnnot; - -pub trait RequiredAnnot { - fn get_annot(a: &A) -> SimpleType; -} -impl<'ty, T> RequiredAnnot> for T { - fn get_annot(a: &ManualAnnot<'ty>) -> SimpleType { - a.0.clone() - } -} -impl RequiredAnnot for T { - fn get_annot(_: &StaticAnnot) -> SimpleType { - T::static_type() - } -} +use crate::options::{HasAnnot, ManualAnnot, NoAnnot, StaticAnnot, TypeAnnot}; +use crate::{Result, SimpleType, ToDhall}; #[derive(Debug, Clone)] pub struct Serializer<'a, T, A> { @@ -46,12 +26,15 @@ impl<'a, T> Serializer<'a, T, NoAnnot> { } } -impl<'a, T, A> Serializer<'a, T, A> { +impl<'a, T, A> Serializer<'a, T, A> +where + A: TypeAnnot, +{ pub fn to_string(&self) -> Result where - T: ToDhall + RequiredAnnot, + T: ToDhall + HasAnnot, { - let val = self.data.to_dhall(&T::get_annot(&self.annot))?; + let val = self.data.to_dhall(T::get_annot(self.annot).as_ref())?; Ok(val.to_string()) } } -- cgit v1.2.3