Enum serde_dhall::SimpleType [−][src]
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
Corresponds to the Dhall type Bool
Corresponds to the Dhall type Natural
Corresponds to the Dhall type Integer
Corresponds to the Dhall type Double
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
impl Clone for SimpleType
[src]
fn clone(&self) -> SimpleType
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Debug for SimpleType
[src]
impl Display for SimpleType
[src]
impl Eq for SimpleType
[src]
impl FromDhall for SimpleType
[src]
fn from_dhall(v: &Value) -> Result<Self>
[src]
impl PartialEq<SimpleType> for SimpleType
[src]
fn eq(&self, other: &SimpleType) -> bool
[src]
fn ne(&self, other: &SimpleType) -> bool
[src]
impl StructuralEq for SimpleType
[src]
impl StructuralPartialEq for SimpleType
[src]
Auto Trait Implementations
impl RefUnwindSafe for SimpleType
[src]
impl Send for SimpleType
[src]
impl Sync for SimpleType
[src]
impl Unpin for SimpleType
[src]
impl UnwindSafe for SimpleType
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<Q, K> Equivalent<K> for Q where
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
[src]
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
pub fn equivalent(&self, key: &K) -> bool
[src]
impl<T> From<T> for T
[src]
impl<T> Instrument for T
[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>
[src]
pub fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T> Instrument for T
[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>
[src]
pub fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,