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§

source§

impl Clone for SimpleValue

source§

fn clone(&self) -> SimpleValue

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for SimpleValue

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'de> Deserialize<'de> for SimpleValue

source§

fn deserialize<D>(deserializer: D) -> Result<SimpleValue, D::Error>where
    D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl PartialEq<SimpleValue> for SimpleValue

source§

fn eq(&self, other: &SimpleValue) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for SimpleValue

source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>where
    S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Eq for SimpleValue

source§

impl StructuralEq for SimpleValue

source§

impl StructuralPartialEq for SimpleValue

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere
    T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere
    T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere
    T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<Q, K> Equivalent<K> for Qwhere
    Q: Eq + ?Sized,
    K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

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

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

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

fn in_current_span(self) -> Instrumented<Self>

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

impl<T, U> Into<U> for Twhere
    U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere
    T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for Twhere
    U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere
    U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

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
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<T> DeserializeOwned for Twhere
    T: for<'de> Deserialize<'de>,