-
Notifications
You must be signed in to change notification settings - Fork 132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Any reason for not providing Uuid wrapper just like UtcDataTime? #174
Comments
Currently I'm using small conversion function like fn uuid_to_bson(uuid: Uuid) -> Bson {
Bson::Binary(BinarySubtype::Uuid, uuid.as_bytes().to_vec())
}
fn uuid_from_bson(bson: Bson) -> anyhow::Result<Uuid> {
match bson {
Bson::Binary(BinarySubtype::Uuid, bytes) => Ok(Uuid::from_slice(bytes.as_slice())?),
_ => Err(anyhow::anyhow!("given Bson is not Uuid")),
}
} |
Thanks for filing this issue! I filed RUST-465 on our jira project to track the work for it. |
@patrickfreed Thank you so much! |
Hi @AtsukiTak! RUST-506 introduces a
|
This conversion is not working for me for Rust version 1.70. So I adapted it (especially the restructuring) and implemented a trait for it like below. trait BsonUuidConversion {
fn as_uuid(&self) -> anyhow::Result<uuid::Uuid>;
}
impl BsonUuidConversion for Bson {
fn as_uuid(&self) -> anyhow::Result<uuid::Uuid> {
match self {
Bson::Binary(binary) => match binary {
mongodb::bson::binary::Binary {
subtype: _BinarySubtype,
bytes,
} => Ok(uuid::Uuid::from_slice(bytes.as_slice())?),
_ => Err(anyhow::anyhow!("given Bson is not Uuid")),
},
_ => Err(anyhow::anyhow!("given Bson is not Uuid")),
}
}
}
let bsonUuid : Bson = ...;
let uuid = bsonUuid.as_uuid(); |
Hi there! Thanks for all of your great work!
In my project, I want to use Uuid as document field, but it seems not to easy.
When I serialize
Uuid
intoBson
, it always serialized asString
because of its original implementation.I think this situation is pretty similar to
DateTime<Utc>
whose thin wrapper is provided by this crate.Is there any reason for not providing
Uuid
wrapper?If it is provided, it would be very useful for me.
Sorry if I missed something. I'm pretty new to this crate.
Thanks.
The text was updated successfully, but these errors were encountered: