summaryrefslogtreecommitdiff
path: root/dhall/src/api/mod.rs
blob: 0a0ef93a8ee6dc8815b2d4de51fcd9975d70f497 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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()))
    }
}