use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(tag = "kind", rename_all = "snake_case")]
pub enum DataValue {
Null,
Bool {
value: bool,
},
Int {
value: i64,
},
Float {
value: f64,
},
Text {
value: String,
},
Bytes {
value: Vec<u8>,
},
Attachment {
hash: String,
size: u64,
#[serde(default, skip_serializing_if = "Option::is_none")]
name: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
mime: Option<String>,
},
}
impl DataValue {
pub fn text(value: impl Into<String>) -> Self {
Self::Text {
value: value.into(),
}
}
pub fn int(value: i64) -> Self {
Self::Int { value }
}
pub fn bool(value: bool) -> Self {
Self::Bool { value }
}
pub fn float(value: f64) -> Self {
Self::Float { value }
}
pub fn bytes(value: impl Into<Vec<u8>>) -> Self {
Self::Bytes {
value: value.into(),
}
}
pub fn attachment(hash: impl Into<String>, size: u64) -> Self {
Self::Attachment {
hash: hash.into(),
size,
name: None,
mime: None,
}
}
}