Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion crates/dao/src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ macro_rules! impl_to_value {
impl<'a> ToValue for &'a $ty {
fn to_value(&self) -> Value { (*self).into() }
}

impl<'a> ToValue for &'a Option<$ty> {
fn to_value(&self) -> Value { (*self).into() }
}
};
}

Expand All @@ -122,7 +126,7 @@ macro_rules! impl_from {

/// For dobule borrowed types
impl<'a> From<&&'a $ty> for Value {
fn from(f: &&'a $ty) -> Self { Value::$variant(f.to_owned().to_owned()) }
fn from(f: &&'a $ty) -> Self { (*f).into() }
}

/// for borrowed option types
Expand All @@ -135,6 +139,13 @@ macro_rules! impl_from {
}
}

/// for dobule borrowed option types
impl<'a> From<&&'a Option<$ty>> for Value {
fn from(f: &&'a Option<$ty>) -> Self {
(*f).into()
}
}

impl_to_value!($ty);
};

Expand Down Expand Up @@ -187,10 +198,23 @@ impl<'a> From<&&'a str> for Value {
fn from(f: &&'a str) -> Value { Value::Text(f.to_string()) }
}

impl<'a> From<&'a Option<&'a str>> for Value {
fn from(f: &'a Option<&'a str>) -> Value {
match f {
Some(f) => Value::Text(f.to_string()),
None => Value::Nil
}
}
}

impl ToValue for &str {
fn to_value(&self) -> Value { Value::Text(self.to_string()) }
}

impl ToValue for Option<&str> {
fn to_value(&self) -> Value { self.into() }
}

impl From<Vec<String>> for Value {
fn from(f: Vec<String>) -> Value { Value::Array(Array::Text(f)) }
}
Expand Down