Enum serde_dhall::SimpleValue
source · pub enum SimpleValue {
Num(NumKind),
Text(String),
Optional(Option<Box<SimpleValue>>),
List(Vec<SimpleValue>),
Record(BTreeMap<String, SimpleValue>),
Union(String, Option<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(String, Option<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
impl Clone for SimpleValue
source§fn clone(&self) -> SimpleValue
fn clone(&self) -> SimpleValue
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for SimpleValue
impl Debug for SimpleValue
source§impl<'de> Deserialize<'de> for SimpleValue
impl<'de> Deserialize<'de> for SimpleValue
source§fn deserialize<D>(deserializer: D) -> Result<SimpleValue, D::Error>where
D: Deserializer<'de>,
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
impl PartialEq<SimpleValue> for SimpleValue
source§fn eq(&self, other: &SimpleValue) -> bool
fn eq(&self, other: &SimpleValue) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.source§impl Serialize for SimpleValue
impl Serialize for SimpleValue
impl Eq for SimpleValue
impl StructuralEq for SimpleValue
impl StructuralPartialEq for SimpleValue
Auto Trait Implementations§
impl RefUnwindSafe for SimpleValue
impl Send for SimpleValue
impl Sync for SimpleValue
impl Unpin for SimpleValue
impl UnwindSafe for SimpleValue
Blanket Implementations§
source§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.