bson-rust
bson-rust copied to clipboard
How to use in wasm context?
When used bson = "2.3" directly as dependency,
building output the following error message:
error: the wasm32-unknown-unknown target is not supported by default, you may need to enable the "js" feature. For more information see: https://docs.rs/getrandom/#webassembly-support
Then, after added getrandom = { version = "0.2.7", features = ["js"] } under bson dependency,
building output error message became:
error[E0599]: no function or associated item named new_v4found for structuuid::Uuid in the current scope
How can I use this crate in wasm context?
Thx.
I believe the error you're seeing may not be related to wasm or bson, but instead that you need to enable the v4 feature flag for your dependency on the uuid crate. Alternatively, you can switch to use bson::Uuid instead.
Note that bson currently doesn't have any interop with v1 of uuid (we currently only support 0.8 via the uuid-0_8 feature flag), but we're adding it soon (see #355). This may also be what you're experiencing. If so, you can work around it by downgrading your uuid dependency to 0.8 until we release support for 1.0.
I believe the error you're seeing may not be related to wasm or
bson, but instead that you need to enable thev4feature flag for your dependency on theuuidcrate. Alternatively, you can switch to usebson::Uuidinstead.Note that
bsoncurrently doesn't have any interop with v1 ofuuid(we currently only support0.8via theuuid-0_8feature flag), but we're adding it soon (see #355). This may also be what you're experiencing. If so, you can work around it by downgrading youruuiddependency to 0.8 until we release support for 1.0.
I didn't use uuid for dependency directly.
My crate aims to build an serializable entity model with the following id field:
#[serde(rename = "_id")]
#[serde(skip_serializing_if = "Option::is_none")]
pub id: Option<bson::oid::ObjectId>,
Now, I just add bson dependency this way to make it work:
bson = { git = "https://github.com/mongodb/bson-rust", features = ["uuid-1"] }
getrandom = { version = "0.2.7", features = ["js"] }
Looking forward to new bson release.
Thanks.
FYI, 2.4.0 has been released with the uuid-1 flag.