Enum serde_dhall::SimpleType
source · [−]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 SimpleType
s 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:
Dhall | Rust |
---|---|
Bool | bool |
Natural | u64 , u32 , … |
Integer | i64 , i32 , … |
Double | f64 , f32 , … |
Text | String |
List T | Vec<T> |
Optional T | Option<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 T | HashMap<String, T> , structs |
T -> U | unsupported |
Prelude.JSON.Type | unsupported |
Prelude.Map.Type T U | unsupported |
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
sourceimpl Clone for SimpleType
impl Clone for SimpleType
sourcefn clone(&self) -> SimpleType
fn clone(&self) -> SimpleType
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for SimpleType
impl Debug for SimpleType
sourceimpl Display for SimpleType
impl Display for SimpleType
sourceimpl PartialEq<SimpleType> for SimpleType
impl PartialEq<SimpleType> for SimpleType
sourcefn eq(&self, other: &SimpleType) -> bool
fn eq(&self, other: &SimpleType) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourcefn ne(&self, other: &SimpleType) -> bool
fn ne(&self, other: &SimpleType) -> bool
This method tests for !=
.
impl Eq for SimpleType
impl FromDhall for SimpleType
impl StructuralEq for SimpleType
impl StructuralPartialEq for SimpleType
Auto Trait Implementations
impl RefUnwindSafe for SimpleType
impl Send for SimpleType
impl Sync for SimpleType
impl Unpin for SimpleType
impl UnwindSafe for SimpleType
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
sourcefn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to key
and return true
if they are equal.
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more