A Rust library for encoding and decoding BSON (Binary JSON) with Serde integration.
bson is a Rust library for encoding and decoding BSON (Binary JSON), a binary serialization format used primarily by MongoDB. It provides both low-level APIs for direct BSON manipulation and high-level Serde integration for seamless serialization of Rust structs. The crate solves the problem of efficiently converting between Rust data types and BSON for database interactions and data storage.
Rust developers working with MongoDB or any system that uses BSON as a data interchange format, particularly those needing type-safe serialization and deserialization.
Developers choose bson for its official support from MongoDB, robust Serde integration that reduces boilerplate, and comprehensive feature set including WASM support and extensibility via feature flags. It is the standard BSON library in the Rust ecosystem for MongoDB-related projects.
Encoding and decoding support for BSON in Rust
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Models all BSON types via the Bson enum, ensuring accurate representation of MongoDB's data format with type safety.
Provides doc! and bson! macros for easy construction and manipulation of BSON documents, reducing code verbosity as shown in the README examples.
Leverages Serde for automatic serialization/deserialization, allowing strongly-typed Rust structs to be easily converted, reducing boilerplate.
Offers optional features for chrono, uuid, and time crates, enabling flexible datetime and UUID handling without mandatory dependencies.
Compiles to WebAssembly with js-sys support for ObjectId generation, making it suitable for client-side applications.
Managing optional features like chrono-0_4 and uuid-1 adds configuration overhead and can lead to dependency conflicts, as noted in the README's feature flag table.
Enabling features like large_dates can impact performance and introduce parsing ambiguities, and serde_path_to_error incurs CPU and memory overhead.
Features like serde_path_to_error are marked as unstable, meaning breaking changes in dependent crates could affect code relying on them.
Inherently tied to the BSON format, so it's not suitable for projects needing other serialization formats without additional libraries.