mongodb-labs/mongo-rust-driver-prototype

Serialize struct with u32 field

nkostoulas opened this issue · 5 comments

I've been trying to use from_bson() / to_bson() with a struct that has a u32/usize/u64 field but I've been getting the following error:

`Result::unwrap()` on an `Err` value: UnsupportedUnsignedType',

Seems to be a bson-rs issue that is resolved by using the following feature

if cfg!(feature = "u2i")

This doesn't seem to be a part of this library though. Is there a way around it? I'm manually constructing the doc! for now.

saghm commented

Hello! I'm not quite sure what you mean by the fix "not being a part of this library". The driver doesn't actually define any of the BSON functionality, so you'll need to add that as a dependency on your own, and you can specify the u2i feature when you do that.

If you're having issues specifically with the BSON library, would you mind filing an issue with that repository? I can still help you with it there, but it will help others who might have the same issue in the future find the solution we figure out with as well as notifying the owner of that repository, who doesn't generally look at the issues in this repo.

Methods to_bson(), from_bson() are part of this library though so I was asking if you're aware of this issue. It seems not possible to serialise unsigned numbers at the moment. I only ended up checking the bson library because searching for this error online seemed to be part of that codebase.

If this library is internally using bson, shouldn't this feature be added internally?

saghm commented

Those functions are re-exported from the BSON dependency for convenience. I don't think there's a way to optionally include features in the dependency based on whether a feature exists in the library itself, so unfortunately you'll have to manually add the bson crate with that feature as a dependency if you want to use that functionality.

Ok makes sense thanks!

saghm commented

Glad to help!