[][src]Enum serde_dhall::SimpleValue

pub enum SimpleValue {
    Num(NumKind),
    Text(String),
    Optional(Option<Box<SimpleValue>>),
    List(Vec<SimpleValue>),
    Record(BTreeMap<String, SimpleValue>),
    Union(StringOption<Box<SimpleValue>>),
}

A value of the kind that can be decoded by serde_dhall, e.g. { x = True, y = [1, 2, 3] }. This can be obtained with from_str() or from_file(). It can also be deserialized into Rust types with from_simple_value().

Examples

use std::collections::BTreeMap;
use serde::Deserialize;
use serde_dhall::{from_simple_value, NumKind, SimpleValue};

#[derive(Debug, PartialEq, Eq, Deserialize)]
struct Foo {
    x: bool,
    y: Vec<u64>,
}

let value: SimpleValue =
    serde_dhall::from_str("{ x = True, y = [1, 2, 3] }").parse()?;

assert_eq!(
    value,
    SimpleValue::Record({
        let mut r = BTreeMap::new();
        r.insert(
            "x".to_string(),
            SimpleValue::Num(NumKind::Bool(true))
        );
        r.insert(
            "y".to_string(),
            SimpleValue::List(vec![
                SimpleValue::Num(NumKind::Natural(1)),
                SimpleValue::Num(NumKind::Natural(2)),
                SimpleValue::Num(NumKind::Natural(3)),
            ])
        );
        r
    })
);

let foo: Foo = from_simple_value(value)?;

assert_eq!(
    foo,
    Foo {
        x: true,
        y: vec![1, 2, 3]
    }
);
use std::collections::BTreeMap;
use serde_dhall::{NumKind, SimpleValue};

let value: SimpleValue =
    serde_dhall::from_str("{ x = 1, y = 2 }").parse()?;

let mut map = BTreeMap::new();
map.insert("x".to_string(), SimpleValue::Num(NumKind::Natural(1)));
map.insert("y".to_string(), SimpleValue::Num(NumKind::Natural(2)));
assert_eq!(value, SimpleValue::Record(map));

Variants

Num(NumKind)

Numbers and booleans - True, 1, +2, 3.24

Text(String)

A string of text - "Hello world!"

Optional(Option<Box<SimpleValue>>)

An optional value - Some e, None

A list of values - [a, b, c, d, e]

A record value - { k1 = v1, k2 = v2 }

A union value (both the name of the variant and the variant's value) - Left e

Trait Implementations

impl Clone for SimpleValue[src]

impl Debug for SimpleValue[src]

impl Eq for SimpleValue[src]

impl FromDhall for SimpleValue[src]

impl PartialEq<SimpleValue> for SimpleValue[src]

impl StructuralEq for SimpleValue[src]

impl StructuralPartialEq for SimpleValue[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<Q, K> Equivalent<K> for Q where
    K: Borrow<Q> + ?Sized,
    Q: Eq + ?Sized
[src]

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.