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
sourceimpl Clone for SimpleValue
impl Clone for SimpleValue
sourcefn clone(&self) -> SimpleValue
fn clone(&self) -> SimpleValue
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for SimpleValue
impl Debug for SimpleValue
sourceimpl<'de> Deserialize<'de> for SimpleValue
impl<'de> Deserialize<'de> for SimpleValue
sourcefn 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
sourceimpl PartialEq<SimpleValue> for SimpleValue
impl PartialEq<SimpleValue> for SimpleValue
sourcefn 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 ==
. Read more
sourcefn ne(&self, other: &SimpleValue) -> bool
fn ne(&self, other: &SimpleValue) -> bool
This method tests for !=
.
sourceimpl 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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
sourcefn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to key
and return true
if they are equal.
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
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
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more