[][src]Enum serde_dhall::SimpleType

pub enum SimpleType {
    Bool,
    Natural,
    Integer,
    Double,
    Text,
    Optional(Box<SimpleType>),
    List(Box<SimpleType>),
    Record(HashMap<String, SimpleType>),
    Union(HashMap<String, Option<SimpleType>>),
}

The type of a value that can be decoded by serde_dhall, e.g. { x: Bool, y: List Natural }.

A SimpleType is used when deserializing values to ensure they are of the expected type. Rather than letting serde handle potential type mismatches, this uses the type-checking capabilities of Dhall to catch errors early and cleanly indicate in the user's code where the mismatch happened.

You would typically not manipulate SimpleTypes by hand but rather let Rust infer it for your datatype by deriving the StaticType trait, and using Deserializer::static_type_annotation. If you need to supply a SimpleType manually, you can either deserialize it like any other Dhall value, or construct it manually.

Examples

use serde_dhall::{SimpleType, StaticType};

#[derive(StaticType)]
struct Foo {
    x: bool,
    y: Vec<u64>,
}

let ty: SimpleType =
    serde_dhall::from_str("{ x: Bool, y: List Natural }").parse()?;

assert_eq!(Foo::static_type(), ty);
use std::collections::HashMap;
use serde_dhall::SimpleType;

let ty: SimpleType =
    serde_dhall::from_str("{ x: Natural, y: Natural }").parse()?;

let mut map = HashMap::new();
map.insert("x".to_string(), SimpleType::Natural);
map.insert("y".to_string(), SimpleType::Natural);
assert_eq!(ty, SimpleType::Record(map));

Variants

Bool

Corresponds to the Dhall type Bool

Natural

Corresponds to the Dhall type Natural

Integer

Corresponds to the Dhall type Integer

Double

Corresponds to the Dhall type Double

Text

Corresponds to the Dhall type Text

Optional(Box<SimpleType>)

Corresponds to the Dhall type Optional T

Corresponds to the Dhall type List T

Corresponds to the Dhall type { x : T, y : U }

Corresponds to the Dhall type < x : T | y : U >

Trait Implementations

impl Clone for SimpleType[src]

impl Debug for SimpleType[src]

impl Eq for SimpleType[src]

impl FromDhall for SimpleType[src]

impl PartialEq<SimpleType> for SimpleType[src]

impl StructuralEq for SimpleType[src]

impl StructuralPartialEq for SimpleType[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<Q, K> Equivalent<K> for Q where
    K: Borrow<Q> + ?Sized,
    Q: Eq + ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.