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

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.

Type correspondence

The following Dhall types correspond to the following Rust types:

DhallRust
Boolbool
Naturalu64, u32, …
Integeri64, i32, …
Doublef64, f32, …
TextString
List TVec<T>
Optional TOption<T>
{ x: T, y: U }structs
{ _1: T, _2: U }(T, U), structs
{ x: T, y: T }HashMap<String, T>, structs
< x: T \| y: U >enums
Prelude.Map.Type Text THashMap<String, T>, structs
T -> Uunsupported
Prelude.JSON.Typeunsupported
Prelude.Map.Type T Uunsupported

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

List(Box<SimpleType>)

Corresponds to the Dhall type List T

Record(HashMap<String, SimpleType>)

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

Union(HashMap<String, Option<SimpleType>>)

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

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Compare self to key and return true if they are equal.

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more