diff options
Diffstat (limited to '')
-rw-r--r-- | dhall/src/api/mod.rs | 40 | ||||
-rw-r--r-- | dhall/src/api/serde.rs (renamed from dhall/src/serde.rs) | 2 | ||||
-rw-r--r-- | dhall/src/api/traits/deserialize.rs (renamed from dhall/src/traits/deserialize.rs) | 2 | ||||
-rw-r--r-- | dhall/src/api/traits/dynamic_type.rs (renamed from dhall/src/traits/dynamic_type.rs) | 9 | ||||
-rw-r--r-- | dhall/src/api/traits/mod.rs (renamed from dhall/src/traits/mod.rs) | 0 | ||||
-rw-r--r-- | dhall/src/api/traits/static_type.rs (renamed from dhall/src/traits/static_type.rs) | 6 |
6 files changed, 48 insertions, 11 deletions
diff --git a/dhall/src/api/mod.rs b/dhall/src/api/mod.rs new file mode 100644 index 0000000..0a0ef93 --- /dev/null +++ b/dhall/src/api/mod.rs @@ -0,0 +1,40 @@ +mod serde; +pub(crate) mod traits; + +/// Deserialization of Dhall expressions into Rust +pub mod de { + #[doc(hidden)] + pub use crate::phase::SimpleType; + pub use crate::traits::{Deserialize, SimpleStaticType, StaticType}; + #[doc(hidden)] + pub use dhall_proc_macros::SimpleStaticType; + + /// Deserialize an instance of type T from a string of Dhall text. + /// + /// This will recursively resolve all imports in the expression, and + /// typecheck it before deserialization. Relative imports will be resolved relative to the + /// provided file. More control over this process is not yet available + /// but will be in a coming version of this crate. + /// + /// If a type is provided, this additionally checks that the provided + /// expression has that type. + pub fn from_str<'a, T: Deserialize<'a>>( + s: &'a str, + ty: Option<&crate::phase::Type>, + ) -> crate::error::Result<T> { + T::from_str(s, ty) + } + + /// Deserialize an instance of type T from a string of Dhall text, + /// additionally checking that it matches the type of T. + /// + /// This will recursively resolve all imports in the expression, and + /// typecheck it before deserialization. Relative imports will be resolved relative to the + /// provided file. More control over this process is not yet available + /// but will be in a coming version of this crate. + pub fn from_str_auto_type<'a, T: Deserialize<'a> + StaticType>( + s: &'a str, + ) -> crate::error::Result<T> { + from_str(s, Some(&<T as StaticType>::get_static_type())) + } +} diff --git a/dhall/src/serde.rs b/dhall/src/api/serde.rs index 96bc765..93921ba 100644 --- a/dhall/src/serde.rs +++ b/dhall/src/api/serde.rs @@ -1,5 +1,5 @@ use crate::error::{Error, Result}; -use crate::expr::{Normalized, Type}; +use crate::phase::{Normalized, Type}; use crate::traits::Deserialize; use dhall_syntax::*; use std::borrow::Cow; diff --git a/dhall/src/traits/deserialize.rs b/dhall/src/api/traits/deserialize.rs index e3ff2d5..9673cf9 100644 --- a/dhall/src/traits/deserialize.rs +++ b/dhall/src/api/traits/deserialize.rs @@ -1,5 +1,5 @@ use crate::error::*; -use crate::expr::*; +use crate::phase::*; /// A data structure that can be deserialized from a Dhall expression /// diff --git a/dhall/src/traits/dynamic_type.rs b/dhall/src/api/traits/dynamic_type.rs index 858642e..7763a28 100644 --- a/dhall/src/traits/dynamic_type.rs +++ b/dhall/src/api/traits/dynamic_type.rs @@ -1,9 +1,6 @@ -use crate::expr::*; +use crate::error::TypeError; +use crate::phase::{Normalized, Type, Typed}; use crate::traits::StaticType; -#[allow(unused_imports)] -use crate::typecheck::{TypeError, TypeMessage, TypecheckContext}; -#[allow(unused_imports)] -use dhall_syntax::{Const, ExprF}; use std::borrow::Cow; pub trait DynamicType { @@ -30,6 +27,6 @@ impl DynamicType for Normalized { impl DynamicType for Typed { fn get_type(&self) -> Result<Cow<'_, Type>, TypeError> { - self.0.get_type() + self.get_type() } } diff --git a/dhall/src/traits/mod.rs b/dhall/src/api/traits/mod.rs index 315e17a..315e17a 100644 --- a/dhall/src/traits/mod.rs +++ b/dhall/src/api/traits/mod.rs diff --git a/dhall/src/traits/static_type.rs b/dhall/src/api/traits/static_type.rs index f90b8df..e05dfff 100644 --- a/dhall/src/traits/static_type.rs +++ b/dhall/src/api/traits/static_type.rs @@ -1,4 +1,4 @@ -use crate::expr::*; +use crate::phase::*; use dhall_proc_macros as dhall; use dhall_syntax::*; @@ -38,8 +38,8 @@ fn mktype(x: SubExpr<X, X>) -> SimpleType { impl<T: SimpleStaticType> StaticType for T { fn get_static_type() -> Type { - crate::expr::Normalized::from_thunk_and_type( - crate::normalize::Thunk::from_normalized_expr( + crate::phase::Normalized::from_thunk_and_type( + crate::core::thunk::Thunk::from_normalized_expr( T::get_simple_static_type().into(), ), Type::const_type(), |