summaryrefslogtreecommitdiff
path: root/serde_dhall/src/options/ser.rs
diff options
context:
space:
mode:
Diffstat (limited to 'serde_dhall/src/options/ser.rs')
-rw-r--r--serde_dhall/src/options/ser.rs33
1 files changed, 8 insertions, 25 deletions
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<A> {
- fn get_annot(a: &A) -> SimpleType;
-}
-impl<'ty, T> RequiredAnnot<ManualAnnot<'ty>> for T {
- fn get_annot(a: &ManualAnnot<'ty>) -> SimpleType {
- a.0.clone()
- }
-}
-impl<T: StaticType> RequiredAnnot<StaticAnnot> 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<String>
where
- T: ToDhall + RequiredAnnot<A>,
+ T: ToDhall + HasAnnot<A>,
{
- 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())
}
}