From 6d2c56cc13303ddea6b7f46d5d34659c6c558d19 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Fri, 20 Dec 2019 19:33:00 +0000 Subject: Seal `Deserialize` trait Fixes #81 --- serde_dhall/src/lib.rs | 9 +++++++-- serde_dhall/src/serde.rs | 2 ++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/serde_dhall/src/lib.rs b/serde_dhall/src/lib.rs index 2863788..d8a94d1 100644 --- a/serde_dhall/src/lib.rs +++ b/serde_dhall/src/lib.rs @@ -179,6 +179,8 @@ pub mod value { } } + impl super::de::sealed::Sealed for Value {} + impl super::de::Deserialize for Value { fn from_dhall(v: &Value) -> Result { Ok(v.clone()) @@ -225,14 +227,17 @@ pub mod de { } } + pub(crate) mod sealed { + pub trait Sealed {} + } + /// A data structure that can be deserialized from a Dhall expression /// /// This is automatically implemented for any type that [serde][serde] /// can deserialize. /// /// This trait cannot be implemented manually. - // TODO: seal trait - pub trait Deserialize: Sized { + pub trait Deserialize: sealed::Sealed + Sized { /// See [serde_dhall::from_str][crate::from_str] fn from_dhall(v: &Value) -> Result; } diff --git a/serde_dhall/src/serde.rs b/serde_dhall/src/serde.rs index cf5efc4..99b9014 100644 --- a/serde_dhall/src/serde.rs +++ b/serde_dhall/src/serde.rs @@ -6,6 +6,8 @@ use dhall::syntax::ExprKind; use crate::de::{Deserialize, Error, Result}; use crate::Value; +impl<'a, T> crate::de::sealed::Sealed for T where T: serde::Deserialize<'a> {} + impl<'a, T> Deserialize for T where T: serde::Deserialize<'a>, -- cgit v1.2.3