pub trait StaticType {
    fn static_type() -> SimpleType;
}
Expand description

A Rust type that can be represented as a Dhall type.

A typical example is Option<bool>, represented by the Dhall expression Optional Bool.

This trait can be automatically derived, and this is the recommended way of implementing it.

Some Rust types cannot implement this trait, because there isn’t a single Dhall type that corresponds to them. For example, HashMap<String, u64> could correspond to multiple different Dhall types, e.g. { foo: Natural, bar: Natural } and { baz: Natural }.

See also the table of type correspondances.

Example

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);

Required Methods§

source

fn static_type() -> SimpleType

Return the Dhall type that represents this type.

Example
use serde::Deserialize;
use serde_dhall::{SimpleType, StaticType};

// Using `derive(StaticType)` here would give it the type `{ _1: List Natural }`.
#[derive(Deserialize)]
#[serde(transparent)]
struct Foo(Vec<u64>);

impl StaticType for Foo {
    fn static_type() -> SimpleType {
        SimpleType::List(Box::new(SimpleType::Natural))
    }
}

let foo = serde_dhall::from_str("[ 1, 2 ]")
    .static_type_annotation()
    .parse::<Foo>()?;

assert_eq!(foo.0, vec![1, 2]);

Implementations on Foreign Types§

source§

impl StaticType for bool

source§

impl StaticType for usize

source§

impl StaticType for u64

source§

impl StaticType for u32

source§

impl StaticType for u16

source§

impl StaticType for isize

source§

impl StaticType for i64

source§

impl StaticType for i32

source§

impl StaticType for f64

source§

impl StaticType for f32

source§

impl StaticType for String

source§

impl StaticType for &str

source§

impl StaticType for ()

source§

impl<A> StaticType for (A,)where
    A: StaticType,

source§

impl<A, B> StaticType for (A, B)where
    A: StaticType,
    B: StaticType,

source§

impl<A, B, C> StaticType for (A, B, C)where
    A: StaticType,
    B: StaticType,
    C: StaticType,

source§

impl<A, B, C, D> StaticType for (A, B, C, D)where
    A: StaticType,
    B: StaticType,
    C: StaticType,
    D: StaticType,

source§

impl<T, E> StaticType for Result<T, E>where
    T: StaticType,
    E: StaticType,

source§

impl<T> StaticType for Option<T>where
    T: StaticType,

source§

impl<T> StaticType for Vec<T>where
    T: StaticType,

source§

impl<'a, T> StaticType for &'a Twhere
    T: StaticType,

Implementors§