From 5b91eaa9d6b70a2ac72fe19f2d21871c8d94b017 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Mon, 6 May 2019 23:21:19 +0200 Subject: Move api-related modules into an api module --- dhall/src/api/mod.rs | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 dhall/src/api/mod.rs (limited to 'dhall/src/api/mod.rs') diff --git a/dhall/src/api/mod.rs b/dhall/src/api/mod.rs new file mode 100644 index 0000000..1522c9c --- /dev/null +++ b/dhall/src/api/mod.rs @@ -0,0 +1,38 @@ +mod serde; +pub(crate) mod traits; + +/// Deserialization of Dhall expressions into Rust +pub mod de { + 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::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 { + from_str(s, Some(&::get_static_type())) + } +} -- cgit v1.2.3