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

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

List(Vec<SimpleValue>)

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

Record(BTreeMap<String, SimpleValue>)

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

Union(StringOption<Box<SimpleValue>>)

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

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Deserialize this value from the given Serde deserializer. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Compare self to key and return true if they are equal.

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more