pub enum DataValue {
None,
String(String),
Number(f64),
Boolean(bool),
List(Vec<DataValue>),
Dict(HashMap<String, DataValue>),
Tuple((Box<DataValue>, Box<DataValue>)),
Binary(Binary),
}
Variants§
None
None Value
Just use for deserialize.
String(String)
String Value
use doson::DataValue;
DataValue::String("hello world".to_string());
Number(f64)
Number Value
use doson::DataValue;
DataValue::Number(10_f64);
Boolean(bool)
Boolean Value
use doson::DataValue;
DataValue::Boolean(true);
List(Vec<DataValue>)
List Value
use doson::DataValue;
DataValue::List(vec![
DataValue::Number(1.0),
DataValue::Number(2.0),
DataValue::Number(3.0)
]);
Dict(HashMap<String, DataValue>)
Dict Value
use doson::DataValue;
DataValue::Dict(std::collections::HashMap::new());
Tuple((Box<DataValue>, Box<DataValue>))
Tuple Value
use doson::DataValue;
DataValue::Tuple(
(
Box::new(DataValue::Boolean(true)),
Box::new(DataValue::Boolean(false))
)
);
Binary(Binary)
Binary Value
use doson::DataValue;
use doson::binary::Binary;
DataValue::Binary(
Binary::build(vec![72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100])
)
// or
let from_base64: = "SGVsbG8gV29ybGQ=";
DataValue::Binary(
Binary::from_base64(from_base64)
)
Implementations§
Source§impl DataValue
impl DataValue
Sourcepub fn from(data: &str) -> Self
pub fn from(data: &str) -> Self
parse &str
to DataValue
type:
- String: “xxx”
- Number: 114514
- Boolean: true
- List: [1,2,3,4,5]
- dict: {“hello”: “world”}
- tuple: (1,2)
use doson::DataValue;
assert_eq!(
DataValue::from("[1,2,3]"),
DataValue::List(vec![
DataValue::Number(1_f64),
DataValue::Number(2_f64),
DataValue::Number(3_f64),
])
);
pub fn from_json(data: &str) -> Self
pub fn to_json(&self) -> String
pub fn weight(&self) -> f64
pub fn size(&self) -> usize
pub fn datatype(&self) -> String
pub fn as_string(&self) -> Option<String>
pub fn as_number(&self) -> Option<f64>
pub fn as_bool(&self) -> Option<bool>
pub fn as_tuple(&self) -> Option<(Box<DataValue>, Box<DataValue>)>
pub fn as_list(&self) -> Option<Vec<DataValue>>
pub fn as_dict(&self) -> Option<HashMap<String, DataValue>>
Trait Implementations§
Source§impl<'de> Deserialize<'de> for DataValue
impl<'de> Deserialize<'de> for DataValue
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Ord for DataValue
impl Ord for DataValue
Source§impl PartialOrd for DataValue
impl PartialOrd for DataValue
impl Eq for DataValue
Auto Trait Implementations§
impl Freeze for DataValue
impl RefUnwindSafe for DataValue
impl Send for DataValue
impl Sync for DataValue
impl Unpin for DataValue
impl UnwindSafe for DataValue
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more