summaryrefslogtreecommitdiff
path: root/serde_dhall/src/options/mod.rs
diff options
context:
space:
mode:
authorNadrieril2020-10-28 23:40:28 +0000
committerGitHub2020-10-28 23:40:28 +0000
commitf8234684b1129dac84d09adfb24bdc0f98448b9b (patch)
tree1440cfb514fa856718074f2b1ebce801459b5c0c /serde_dhall/src/options/mod.rs
parent70727acbda68e104f60ae1dbbe95adbcec08a628 (diff)
parentaf16e9699799f8cfbd228e2832e1d5df3653116b (diff)
Merge pull request #189 from Nadrieril/serialize
Diffstat (limited to 'serde_dhall/src/options/mod.rs')
-rw-r--r--serde_dhall/src/options/mod.rs36
1 files changed, 36 insertions, 0 deletions
diff --git a/serde_dhall/src/options/mod.rs b/serde_dhall/src/options/mod.rs
new file mode 100644
index 0000000..9241c45
--- /dev/null
+++ b/serde_dhall/src/options/mod.rs
@@ -0,0 +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())
+ }
+}