diff options
author | Nadrieril | 2020-10-28 21:45:42 +0000 |
---|---|---|
committer | Nadrieril | 2020-10-28 22:52:41 +0000 |
commit | 3b728aff86a086f71f013b77a715c33748d9f6a8 (patch) | |
tree | 7c1ceba27495481b766b4ea84601d7381530f5c2 /serde_dhall/src/options/mod.rs | |
parent | e070270c3f1f10d46281ed7751ff95e15092e7f4 (diff) |
Make type annotation optional to allow serializing SimpleValue
Diffstat (limited to 'serde_dhall/src/options/mod.rs')
-rw-r--r-- | serde_dhall/src/options/mod.rs | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/serde_dhall/src/options/mod.rs b/serde_dhall/src/options/mod.rs index 384f318..9241c45 100644 --- a/serde_dhall/src/options/mod.rs +++ b/serde_dhall/src/options/mod.rs @@ -1,2 +1,36 @@ +use crate::{SimpleType, StaticType}; + pub(crate) mod de; pub(crate) mod ser; + +#[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 TypeAnnot: Copy {} +pub trait HasAnnot<A: TypeAnnot> { + fn get_annot(a: A) -> Option<SimpleType>; +} + +impl TypeAnnot for NoAnnot {} +impl TypeAnnot for ManualAnnot<'_> {} +impl TypeAnnot for StaticAnnot {} + +impl<T> HasAnnot<NoAnnot> for T { + fn get_annot(_: NoAnnot) -> Option<SimpleType> { + None + } +} +impl<T> HasAnnot<ManualAnnot<'_>> for T { + fn get_annot(a: ManualAnnot<'_>) -> Option<SimpleType> { + Some(a.0.clone()) + } +} +impl<T: StaticType> HasAnnot<StaticAnnot> for T { + fn get_annot(_: StaticAnnot) -> Option<SimpleType> { + Some(T::static_type()) + } +} |