Trait serde_dhall::StaticType [−][src]
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
fn static_type() -> SimpleType
[src]
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
impl StaticType for bool
[src]
fn static_type() -> SimpleType
[src]
impl StaticType for usize
[src]
fn static_type() -> SimpleType
[src]
impl StaticType for u64
[src]
fn static_type() -> SimpleType
[src]
impl StaticType for u32
[src]
fn static_type() -> SimpleType
[src]
impl StaticType for isize
[src]
fn static_type() -> SimpleType
[src]
impl StaticType for i64
[src]
fn static_type() -> SimpleType
[src]
impl StaticType for i32
[src]
fn static_type() -> SimpleType
[src]
impl StaticType for f64
[src]
fn static_type() -> SimpleType
[src]
impl StaticType for f32
[src]
fn static_type() -> SimpleType
[src]
impl StaticType for String
[src]
fn static_type() -> SimpleType
[src]
impl StaticType for &str
[src]
fn static_type() -> SimpleType
[src]
impl StaticType for ()
[src]
fn static_type() -> SimpleType
[src]
impl<A> StaticType for (A,) where
A: StaticType,
[src]
A: StaticType,
fn static_type() -> SimpleType
[src]
impl<A, B> StaticType for (A, B) where
A: StaticType,
B: StaticType,
[src]
A: StaticType,
B: StaticType,
fn static_type() -> SimpleType
[src]
impl<A, B, C> StaticType for (A, B, C) where
A: StaticType,
B: StaticType,
C: StaticType,
[src]
A: StaticType,
B: StaticType,
C: StaticType,
fn static_type() -> SimpleType
[src]
impl<A, B, C, D> StaticType for (A, B, C, D) where
A: StaticType,
B: StaticType,
C: StaticType,
D: StaticType,
[src]
A: StaticType,
B: StaticType,
C: StaticType,
D: StaticType,
fn static_type() -> SimpleType
[src]
impl<T, E> StaticType for Result<T, E> where
T: StaticType,
E: StaticType,
[src]
T: StaticType,
E: StaticType,
fn static_type() -> SimpleType
[src]
impl<T> StaticType for Option<T> where
T: StaticType,
[src]
T: StaticType,
fn static_type() -> SimpleType
[src]
impl<T> StaticType for Vec<T> where
T: StaticType,
[src]
T: StaticType,
fn static_type() -> SimpleType
[src]
impl<'a, T> StaticType for &'a T where
T: StaticType,
[src]
T: StaticType,