Add conversion functionality from Thing to ID

Closes #1454
This commit is contained in:
Tobie Morgan Hitchcock 2022-11-23 08:58:56 +00:00
parent b8d485fe32
commit d4f1c28a4a
2 changed files with 8 additions and 1 deletions

View file

@ -10,6 +10,7 @@ use crate::sql::ident::ident_raw;
use crate::sql::number::integer; use crate::sql::number::integer;
use crate::sql::object::{object, Object}; use crate::sql::object::{object, Object};
use crate::sql::strand::Strand; use crate::sql::strand::Strand;
use crate::sql::thing::Thing;
use crate::sql::uuid::Uuid; use crate::sql::uuid::Uuid;
use crate::sql::value::Value; use crate::sql::value::Value;
use nanoid::nanoid; use nanoid::nanoid;
@ -86,6 +87,12 @@ impl From<Vec<Value>> for Id {
} }
} }
impl From<Thing> for Id {
fn from(v: Thing) -> Self {
v.id
}
}
impl Id { impl Id {
/// Generate a new random ID /// Generate a new random ID
pub fn rand() -> Self { pub fn rand() -> Self {

View file

@ -465,7 +465,7 @@ impl From<Id> for Value {
fn from(v: Id) -> Self { fn from(v: Id) -> Self {
match v { match v {
Id::Number(v) => v.into(), Id::Number(v) => v.into(),
Id::String(v) => Strand::from(v).into(), Id::String(v) => v.into(),
Id::Object(v) => v.into(), Id::Object(v) => v.into(),
Id::Array(v) => v.into(), Id::Array(v) => v.into(),
} }