Merge pull request #875 from serates/master
Add feature(bson-uuid) which will enable Uuid's from the bson crate
This commit is contained in:
commit
4218b8a607
17
src/types/external/bson.rs
vendored
17
src/types/external/bson.rs
vendored
|
@ -2,6 +2,8 @@ use bson::{oid::ObjectId, Bson, Document};
|
||||||
|
|
||||||
#[cfg(feature = "chrono")]
|
#[cfg(feature = "chrono")]
|
||||||
use bson::DateTime as UtcDateTime;
|
use bson::DateTime as UtcDateTime;
|
||||||
|
#[cfg(feature = "bson-uuid")]
|
||||||
|
use bson::Uuid;
|
||||||
#[cfg(feature = "chrono")]
|
#[cfg(feature = "chrono")]
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
|
|
||||||
|
@ -21,6 +23,21 @@ impl ScalarType for ObjectId {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "bson-uuid")]
|
||||||
|
#[Scalar(internal, name = "UUID")]
|
||||||
|
impl ScalarType for Uuid {
|
||||||
|
fn parse(value: Value) -> InputValueResult<Self> {
|
||||||
|
match value {
|
||||||
|
Value::String(s) => Ok(Uuid::parse_str(&s)?),
|
||||||
|
_ => Err(InputValueError::expected_type(value)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn to_value(&self) -> Value {
|
||||||
|
Value::String(self.to_string())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(feature = "chrono")]
|
#[cfg(feature = "chrono")]
|
||||||
#[Scalar(internal, name = "DateTime")]
|
#[Scalar(internal, name = "DateTime")]
|
||||||
impl ScalarType for UtcDateTime {
|
impl ScalarType for UtcDateTime {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user