Add additional From<Value> and TryFrom<Value> implementations (#1410)
This commit is contained in:
parent
d1055e6088
commit
82c9d7da2b
3 changed files with 42 additions and 0 deletions
|
@ -60,6 +60,12 @@ impl From<Vec<Operation>> for Array {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<Array> for Vec<Value> {
|
||||
fn from(s: Array) -> Self {
|
||||
s.0
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for Array {
|
||||
type Target = Vec<Value>;
|
||||
fn deref(&self) -> &Self::Target {
|
||||
|
|
|
@ -34,6 +34,12 @@ impl From<String> for Uuid {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<Uuid> for uuid::Uuid {
|
||||
fn from(s: Uuid) -> Self {
|
||||
s.0
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for Uuid {
|
||||
type Target = uuid::Uuid;
|
||||
fn deref(&self) -> &Self::Target {
|
||||
|
|
|
@ -535,6 +535,36 @@ impl TryFrom<Value> for DateTime<Utc> {
|
|||
}
|
||||
}
|
||||
|
||||
impl TryFrom<Value> for uuid::Uuid {
|
||||
type Error = Error;
|
||||
fn try_from(value: Value) -> Result<Self, Self::Error> {
|
||||
match value {
|
||||
Value::Uuid(x) => Ok(x.into()),
|
||||
_ => Err(Error::TryFromError(value.to_string(), "uuid::Uuid")),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<Value> for Vec<Value> {
|
||||
type Error = Error;
|
||||
fn try_from(value: Value) -> Result<Self, Self::Error> {
|
||||
match value {
|
||||
Value::Array(x) => Ok(x.into()),
|
||||
_ => Err(Error::TryFromError(value.to_string(), "Vec<Value>")),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<Value> for Object {
|
||||
type Error = Error;
|
||||
fn try_from(value: Value) -> Result<Self, Self::Error> {
|
||||
match value {
|
||||
Value::Object(x) => Ok(x),
|
||||
_ => Err(Error::TryFromError(value.to_string(), "Object")),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Value {
|
||||
// -----------------------------------
|
||||
// Initial record value
|
||||
|
|
Loading…
Reference in a new issue