//! Generic Rust value representation for data from the database /// Generic Value representation of data from the any database #[derive(Clone, Debug, PartialEq)] pub enum Value { /// The value is a `NULL` value. Null, /// The value is a signed integer. Integer(i64), /// The value is a floating point number. Real(f64), /// The value is a text string. Text(String), /// The value is a blob of data Blob(Vec), } impl From for Value { fn from(value: String) -> Self { Self::Text(value) } } impl From<&str> for Value { fn from(value: &str) -> Self { Self::Text(value.to_owned()) } } impl From<&&str> for Value { fn from(value: &&str) -> Self { Self::Text(value.to_string()) } } impl From> for Value { fn from(value: Vec) -> Self { Self::Blob(value) } } impl From<&[u8]> for Value { fn from(value: &[u8]) -> Self { Self::Blob(value.to_owned()) } } impl From for Value { fn from(value: u8) -> Self { Self::Integer(value.into()) } } impl From for Value { fn from(value: i64) -> Self { Self::Integer(value) } } impl From for Value { fn from(value: u32) -> Self { Self::Integer(value.into()) } } impl From for Value { fn from(value: bool) -> Self { Self::Integer(if value { 1 } else { 0 }) } } impl From> for Value where T: Into, { fn from(value: Option) -> Self { match value { Some(v) => v.into(), None => Value::Null, } } }