[−][src]Enum serde_dhall::SimpleType
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.
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]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Debug 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
impl Send for SimpleType
impl Sync for SimpleType
impl Unpin for SimpleType
impl UnwindSafe for SimpleType
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,
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,
fn equivalent(&self, key: &K) -> bool
[src]
impl<T> From<T> for T
[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.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
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.
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>,