Merge pull request #55 from IcanDivideBy0/id_from_objectid
Add From<ObjectId> for ID
This commit is contained in:
commit
9469c94b57
|
@ -1,5 +1,6 @@
|
|||
use crate::{Result, ScalarType, Value};
|
||||
use async_graphql_derive::Scalar;
|
||||
use bson::oid::{self, ObjectId};
|
||||
use std::convert::TryInto;
|
||||
use std::num::ParseIntError;
|
||||
use std::ops::{Deref, DerefMut};
|
||||
|
@ -77,6 +78,20 @@ impl TryInto<Uuid> for ID {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<ObjectId> for ID {
|
||||
fn from(object_id: ObjectId) -> ID {
|
||||
ID(object_id.to_hex())
|
||||
}
|
||||
}
|
||||
|
||||
impl TryInto<ObjectId> for ID {
|
||||
type Error = oid::Error;
|
||||
|
||||
fn try_into(self) -> std::result::Result<ObjectId, oid::Error> {
|
||||
ObjectId::with_string(&self.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq<&str> for ID {
|
||||
fn eq(&self, other: &&str) -> bool {
|
||||
self.0.as_str() == *other
|
||||
|
|
Loading…
Reference in New Issue
Block a user