Add additional From<Value> and TryFrom<Value> implementations (#1410)

This commit is contained in:
Aman Sharma 2022-10-28 17:05:01 +05:30 committed by GitHub
parent d1055e6088
commit 82c9d7da2b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 0 deletions

View file

@ -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 { impl Deref for Array {
type Target = Vec<Value>; type Target = Vec<Value>;
fn deref(&self) -> &Self::Target { fn deref(&self) -> &Self::Target {

View file

@ -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 { impl Deref for Uuid {
type Target = uuid::Uuid; type Target = uuid::Uuid;
fn deref(&self) -> &Self::Target { fn deref(&self) -> &Self::Target {

View file

@ -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 { impl Value {
// ----------------------------------- // -----------------------------------
// Initial record value // Initial record value