diff --git a/.evergreen/aws-lambda-test/README.md b/.evergreen/aws-lambda-test/README.md index 9cdaf456d..1affe1c5e 100644 --- a/.evergreen/aws-lambda-test/README.md +++ b/.evergreen/aws-lambda-test/README.md @@ -33,7 +33,7 @@ To deploy the application, you need the folllowing tools: * SAM CLI - [Install the SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html) * Docker - [Install Docker community edition](https://hub.docker.com/search/?type=edition&offering=community) -* [Rust](https://www.rust-lang.org/) version 1.74.0 or newer +* [Rust](https://www.rust-lang.org/) version 1.81.0 or newer * [cargo-lambda](https://github.com/cargo-lambda/cargo-lambda) for cross-compilation To build and deploy your application for the first time, run the following in your shell: diff --git a/.evergreen/compile-only.sh b/.evergreen/compile-only.sh index bc8551082..beb95f37f 100755 --- a/.evergreen/compile-only.sh +++ b/.evergreen/compile-only.sh @@ -9,9 +9,6 @@ source ./.evergreen/env.sh if [ "$RUST_VERSION" != "" ]; then rustup toolchain install $RUST_VERSION TOOLCHAIN="+${RUST_VERSION}" - # Remove the local git dependencies for bson and mongocrypt, which don't work properly with the MSRV resolver. - sed -i "s/bson =.*/bson = \"2\"/" Cargo.toml - sed -i "s/mongocrypt =.*/mongocrypt = { version = \"0.2\", optional = true }/" Cargo.toml CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS=fallback cargo +nightly -Zmsrv-policy generate-lockfile fi @@ -22,4 +19,4 @@ cargo $TOOLCHAIN build cargo $TOOLCHAIN build --all-features # Test with no default features. -cargo $TOOLCHAIN build --no-default-features --features compat-3-0-0,rustls-tls +cargo $TOOLCHAIN build --no-default-features --features compat-3-3-0,bson-3,rustls-tls diff --git a/.evergreen/config.yml b/.evergreen/config.yml index fc7c8c27f..2472476c0 100644 --- a/.evergreen/config.yml +++ b/.evergreen/config.yml @@ -795,7 +795,7 @@ tasks: - func: "compile only" vars: # Our minimum supported Rust version. This should be updated whenever the MSRV is bumped. - RUST_VERSION: 1.74.0 + RUST_VERSION: 1.81.0 - name: check-cargo-deny commands: diff --git a/Cargo.lock b/Cargo.lock index 1429954ce..236e246fe 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -214,8 +214,30 @@ dependencies = [ [[package]] name = "bson" -version = "2.14.0" -source = "git+https://github.com/mongodb/bson-rust?branch=main#fdbf863ab5531ade49c09a27019b32e3573ad437" +version = "2.15.0" +source = "git+https://github.com/mongodb/bson-rust?branch=2.15.x#f6f163095b5159ce175424b0e02f9bd7acfaddf2" +dependencies = [ + "ahash", + "base64 0.22.1", + "bitvec", + "getrandom 0.2.16", + "getrandom 0.3.2", + "hex", + "indexmap 2.9.0", + "js-sys", + "once_cell", + "rand 0.9.1", + "serde", + "serde_bytes", + "serde_json", + "time", + "uuid", +] + +[[package]] +name = "bson" +version = "3.0.0" +source = "git+https://github.com/mongodb/bson-rust?branch=main#fe284454c2e55d65f64c3dc067c0ab196be643db" dependencies = [ "ahash", "base64 0.22.1", @@ -1479,10 +1501,11 @@ dependencies = [ [[package]] name = "mongocrypt" -version = "0.2.1" -source = "git+https://github.com/mongodb/libmongocrypt-rust.git?branch=main#c333ab07e36f72ac3a4fd8c9f1ff96a98e60ea3e" +version = "0.3.0" +source = "git+https://github.com/mongodb/libmongocrypt-rust.git?branch=main#6e4bb967f47ea564102e0a0a6d27468d2949e381" dependencies = [ - "bson", + "bson 2.15.0", + "bson 3.0.0", "mongocrypt-sys", "once_cell", "serde", @@ -1491,7 +1514,7 @@ dependencies = [ [[package]] name = "mongocrypt-sys" version = "0.1.4+1.12.0" -source = "git+https://github.com/mongodb/libmongocrypt-rust.git?branch=main#c333ab07e36f72ac3a4fd8c9f1ff96a98e60ea3e" +source = "git+https://github.com/mongodb/libmongocrypt-rust.git?branch=main#6e4bb967f47ea564102e0a0a6d27468d2949e381" [[package]] name = "mongodb" @@ -1503,7 +1526,8 @@ dependencies = [ "backtrace", "base64 0.13.1", "bitflags 1.3.2", - "bson", + "bson 2.15.0", + "bson 3.0.0", "chrono", "ctrlc", "derive-where", diff --git a/Cargo.toml b/Cargo.toml index b612f8998..df35d4758 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ license = "Apache-2.0" readme = "README.md" name = "mongodb" version = "3.2.3" -rust-version = "1.74" +rust-version = "1.81" exclude = [ "etc/**", @@ -30,7 +30,10 @@ exclude = [ [features] default = ["compat-3-0-0", "rustls-tls", "dns-resolver"] -compat-3-0-0 = [] +compat-3-0-0 = ["compat-3-3-0", "bson-2"] +compat-3-3-0 = [] +bson-2 = ["dep:bson2", "mongocrypt/bson-2"] +bson-3 = ["dep:bson3", "mongocrypt/bson-3"] sync = [] rustls-tls = ["dep:rustls", "dep:tokio-rustls"] openssl-tls = ["dep:openssl", "dep:openssl-probe", "dep:tokio-openssl"] @@ -73,7 +76,6 @@ tracing-unstable = ["dep:tracing", "dep:log"] async-trait = "0.1.42" base64 = "0.13.0" bitflags = "1.1.0" -bson = { git = "https://github.com/mongodb/bson-rust", branch = "main", version = "2.14.0" } chrono = { version = "0.4.7", default-features = false, features = [ "clock", "std", @@ -92,7 +94,6 @@ hmac = "0.12.1" once_cell = "1.19.0" log = { version = "0.4.17", optional = true } md-5 = "0.10.1" -mongocrypt = { git = "https://github.com/mongodb/libmongocrypt-rust.git", branch = "main", optional = true, version = "0.2.1" } mongodb-internal-macros = { path = "macros", version = "3.2.3" } num_cpus = { version = "1.13.1", optional = true } openssl = { version = "0.10.38", optional = true } @@ -120,6 +121,27 @@ zstd = { version = "0.11.2", optional = true } macro_magic = "0.5.1" rustversion = "1.0.20" +[dependencies.bson2] +git = "https://github.com/mongodb/bson-rust" +branch = "2.15.x" +package = "bson" +version = "2.15.0" +optional = true + +[dependencies.bson3] +git = "https://github.com/mongodb/bson-rust" +branch = "main" +package = "bson" +version = "3.0.0" +optional = true + +[dependencies.mongocrypt] +git = "https://github.com/mongodb/libmongocrypt-rust.git" +branch = "main" +version = "0.3.0" +default-features = false +optional = true + [dependencies.pbkdf2] version = "0.11.0" default-features = false diff --git a/README.md b/README.md index 7b1987a07..4ef2138cd 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ For more details, including features, runnable examples, troubleshooting resourc ## Installation ### Requirements -- Rust 1.74.0+ (See the [MSRV policy](#minimum-supported-rust-version-msrv-policy) for more information) +- Rust 1.81.0+ (See the [MSRV policy](#minimum-supported-rust-version-msrv-policy) for more information) - MongoDB 4.0+ #### Supported Platforms @@ -149,7 +149,7 @@ Commits to main are run automatically on [evergreen](https://evergreen.mongodb.c ## Minimum supported Rust version (MSRV) policy -The MSRV for this crate is currently 1.74.0. Increases to the MSRV will only happen in a minor or major version release, and will be to a Rust version at least six months old. +The MSRV for this crate is currently 1.81.0. Increases to the MSRV will only happen in a minor or major version release, and will be to a Rust version at least six months old. ## License diff --git a/clippy.toml b/clippy.toml index 3b9db9dfe..5e90250c4 100644 --- a/clippy.toml +++ b/clippy.toml @@ -1 +1 @@ -msrv = "1.74.0" +msrv = "1.81.0" diff --git a/src/action.rs b/src/action.rs index d87d7d69e..91ebc6fd4 100644 --- a/src/action.rs +++ b/src/action.rs @@ -88,8 +88,7 @@ pub trait Action: private::Sealed + IntoFuture { /// If the value is `Some`, call the provided function on `self`. Convenient for chained /// updates with values that need to be set conditionally. For example: /// ```rust - /// # use mongodb::{Client, error::Result}; - /// # use bson::Document; + /// # use mongodb::{Client, error::Result, bson::Document}; /// use mongodb::action::Action; /// async fn list_my_collections(client: &Client, filter: Option) -> Result> { /// client.database("my_db") diff --git a/src/action/aggregate.rs b/src/action/aggregate.rs index 4c7a0ac31..deca70703 100644 --- a/src/action/aggregate.rs +++ b/src/action/aggregate.rs @@ -1,6 +1,6 @@ use std::{marker::PhantomData, time::Duration}; -use bson::{Bson, Document}; +use crate::bson::{Bson, Document}; use crate::{ coll::options::{AggregateOptions, Hint}, diff --git a/src/action/count.rs b/src/action/count.rs index 7c79a27cf..c99aeb26a 100644 --- a/src/action/count.rs +++ b/src/action/count.rs @@ -1,4 +1,4 @@ -use bson::{Bson, Document}; +use crate::bson::{Bson, Document}; use std::time::Duration; use crate::{ diff --git a/src/action/create_collection.rs b/src/action/create_collection.rs index a2362461b..2aa1cec55 100644 --- a/src/action/create_collection.rs +++ b/src/action/create_collection.rs @@ -1,4 +1,4 @@ -use bson::{Bson, Document}; +use crate::bson::{Bson, Document}; use std::time::Duration; use crate::{ diff --git a/src/action/create_index.rs b/src/action/create_index.rs index 2c2decfee..75dc2ba8d 100644 --- a/src/action/create_index.rs +++ b/src/action/create_index.rs @@ -1,6 +1,6 @@ use std::{marker::PhantomData, time::Duration}; -use bson::Bson; +use crate::bson::Bson; use crate::{ coll::options::{CommitQuorum, CreateIndexOptions}, diff --git a/src/action/csfle/create_encrypted_collection.rs b/src/action/csfle/create_encrypted_collection.rs index 43d4cb5ed..141f210bc 100644 --- a/src/action/csfle/create_encrypted_collection.rs +++ b/src/action/csfle/create_encrypted_collection.rs @@ -1,6 +1,6 @@ use std::time::Duration; -use bson::{doc, Bson, Document}; +use crate::bson::{doc, Bson, Document}; use crate::{ action::{action_impl, export_doc, option_setters, options_doc}, diff --git a/src/action/csfle/encrypt.rs b/src/action/csfle/encrypt.rs index 12154e071..1e2c99fcd 100644 --- a/src/action/csfle/encrypt.rs +++ b/src/action/csfle/encrypt.rs @@ -1,4 +1,4 @@ -use bson::{Binary, Bson, RawDocumentBuf}; +use crate::bson::{Binary, Bson, RawDocumentBuf}; use macro_magic::export_tokens; use mongocrypt::ctx::Algorithm; use serde::Serialize; @@ -22,7 +22,7 @@ impl ClientEncryption { #[options_doc(encrypt)] pub fn encrypt( &self, - value: impl Into, + value: impl Into, key: impl Into, algorithm: Algorithm, ) -> Encrypt { @@ -101,7 +101,7 @@ pub struct Encrypt<'a, Mode = Value> { } pub struct Value { - pub(crate) value: bson::RawBson, + pub(crate) value: crate::bson::RawBson, } pub struct Expression { diff --git a/src/action/delete.rs b/src/action/delete.rs index 7168b1c35..4bf2dd78a 100644 --- a/src/action/delete.rs +++ b/src/action/delete.rs @@ -1,4 +1,4 @@ -use bson::{Bson, Document}; +use crate::bson::{Bson, Document}; use crate::{ coll::options::{DeleteOptions, Hint}, diff --git a/src/action/distinct.rs b/src/action/distinct.rs index 822df3b7c..447238f7e 100644 --- a/src/action/distinct.rs +++ b/src/action/distinct.rs @@ -1,6 +1,6 @@ use std::time::Duration; -use bson::{Bson, Document}; +use crate::bson::{Bson, Document}; use crate::{ coll::options::{DistinctOptions, Hint}, diff --git a/src/action/drop.rs b/src/action/drop.rs index ef06075f9..3571a53ed 100644 --- a/src/action/drop.rs +++ b/src/action/drop.rs @@ -1,5 +1,5 @@ #[cfg(feature = "in-use-encryption")] -use bson::Document; +use crate::bson::Document; use crate::{ coll::options::DropCollectionOptions, diff --git a/src/action/drop_index.rs b/src/action/drop_index.rs index 23b08d2e7..e729d3aba 100644 --- a/src/action/drop_index.rs +++ b/src/action/drop_index.rs @@ -1,6 +1,6 @@ use std::time::Duration; -use bson::Bson; +use crate::bson::Bson; use crate::{ coll::options::DropIndexOptions, diff --git a/src/action/find.rs b/src/action/find.rs index 17586f0f6..7730e25e2 100644 --- a/src/action/find.rs +++ b/src/action/find.rs @@ -1,6 +1,6 @@ use std::time::Duration; -use bson::{Bson, Document}; +use crate::bson::{Bson, Document}; use serde::de::DeserializeOwned; use crate::{ diff --git a/src/action/find_and_modify.rs b/src/action/find_and_modify.rs index c21a9cee1..02bfed20e 100644 --- a/src/action/find_and_modify.rs +++ b/src/action/find_and_modify.rs @@ -1,6 +1,6 @@ use std::{borrow::Borrow, time::Duration}; -use bson::{Bson, Document, RawDocumentBuf}; +use crate::bson::{Bson, Document, RawDocumentBuf}; use serde::{de::DeserializeOwned, Serialize}; use crate::{ @@ -107,7 +107,7 @@ impl Collection { FindOneAndReplace { coll: self, filter, - replacement: bson::to_raw_document_buf(replacement.borrow()).map_err(Into::into), + replacement: crate::bson::to_raw_document_buf(replacement.borrow()).map_err(Into::into), options: None, session: None, } diff --git a/src/action/gridfs/delete.rs b/src/action/gridfs/delete.rs index 7f550ee94..99c0534fd 100644 --- a/src/action/gridfs/delete.rs +++ b/src/action/gridfs/delete.rs @@ -1,4 +1,4 @@ -use bson::{doc, Bson}; +use crate::bson::{doc, Bson}; #[cfg(docsrs)] use crate::gridfs::FilesCollectionDocument; @@ -108,7 +108,7 @@ impl<'a> Action for DeleteByName<'a> { .find(doc! { "filename": self.filename.clone() }) .projection(doc! { "_id": 1 }) .await? - .with_type::() + .with_type::() .map(|r| match r { Ok(mut d) => d .remove("_id") diff --git a/src/action/gridfs/download.rs b/src/action/gridfs/download.rs index 38730e678..888608e80 100644 --- a/src/action/gridfs/download.rs +++ b/src/action/gridfs/download.rs @@ -1,4 +1,4 @@ -use bson::{doc, Bson}; +use crate::bson::{doc, Bson}; use crate::{ action::{action_impl, deeplink, export_doc, option_setters, options_doc}, diff --git a/src/action/gridfs/find.rs b/src/action/gridfs/find.rs index 1d3234f34..df96b9787 100644 --- a/src/action/gridfs/find.rs +++ b/src/action/gridfs/find.rs @@ -1,6 +1,6 @@ use std::time::Duration; -use bson::Document; +use crate::bson::Document; use crate::{ action::{action_impl, deeplink, export_doc, option_setters, options_doc}, diff --git a/src/action/gridfs/rename.rs b/src/action/gridfs/rename.rs index 15e2d8d8c..b60a28d52 100644 --- a/src/action/gridfs/rename.rs +++ b/src/action/gridfs/rename.rs @@ -1,4 +1,4 @@ -use bson::{doc, Bson}; +use crate::bson::{doc, Bson}; use crate::{ action::action_impl, diff --git a/src/action/gridfs/upload.rs b/src/action/gridfs/upload.rs index 546efb5f6..f313c455b 100644 --- a/src/action/gridfs/upload.rs +++ b/src/action/gridfs/upload.rs @@ -1,4 +1,4 @@ -use bson::{oid::ObjectId, Bson, Document}; +use crate::bson::{oid::ObjectId, Bson, Document}; #[cfg(docsrs)] use crate::gridfs::FilesCollectionDocument; diff --git a/src/action/insert_many.rs b/src/action/insert_many.rs index 82481d8e1..ab5d7a289 100644 --- a/src/action/insert_many.rs +++ b/src/action/insert_many.rs @@ -1,6 +1,6 @@ use std::{borrow::Borrow, collections::HashSet, ops::Deref}; -use bson::{Bson, RawDocumentBuf}; +use crate::bson::{Bson, RawDocumentBuf}; use serde::Serialize; use crate::{ @@ -34,7 +34,7 @@ impl Collection { coll: CollRef::new(self), docs: docs .into_iter() - .map(|v| bson::to_raw_document_buf(v.borrow()).map_err(Into::into)) + .map(|v| crate::bson::to_raw_document_buf(v.borrow()).map_err(Into::into)) .collect(), options: None, session: None, diff --git a/src/action/insert_one.rs b/src/action/insert_one.rs index 057312f0f..73fba689c 100644 --- a/src/action/insert_one.rs +++ b/src/action/insert_one.rs @@ -1,6 +1,6 @@ use std::{borrow::Borrow, ops::Deref}; -use bson::{Bson, RawDocumentBuf}; +use crate::bson::{Bson, RawDocumentBuf}; use serde::Serialize; use crate::{ @@ -32,7 +32,7 @@ impl Collection { pub fn insert_one(&self, doc: impl Borrow) -> InsertOne { InsertOne { coll: CollRef::new(self), - doc: bson::to_raw_document_buf(doc.borrow()).map_err(Into::into), + doc: crate::bson::to_raw_document_buf(doc.borrow()).map_err(Into::into), options: None, session: None, } diff --git a/src/action/list_collections.rs b/src/action/list_collections.rs index 87c703b56..21f261fb5 100644 --- a/src/action/list_collections.rs +++ b/src/action/list_collections.rs @@ -1,6 +1,6 @@ use std::marker::PhantomData; -use bson::{Bson, Document}; +use crate::bson::{Bson, Document}; use futures_util::TryStreamExt; use crate::{ diff --git a/src/action/list_databases.rs b/src/action/list_databases.rs index 44bf9b1ba..34b4942e8 100644 --- a/src/action/list_databases.rs +++ b/src/action/list_databases.rs @@ -1,6 +1,6 @@ use std::marker::PhantomData; -use bson::{Bson, Document}; +use crate::bson::{Bson, Document}; #[cfg(feature = "sync")] use crate::sync::Client as SyncClient; @@ -106,7 +106,8 @@ impl<'a> Action for ListDatabases<'a, ListSpecifications> { .and_then(|dbs| { dbs.into_iter() .map(|db_spec| { - bson::from_slice(db_spec.as_bytes()).map_err(crate::error::Error::from) + crate::bson::from_slice(db_spec.as_bytes()) + .map_err(crate::error::Error::from) }) .collect() }) diff --git a/src/action/list_indexes.rs b/src/action/list_indexes.rs index e5ce95eed..acbf4bbde 100644 --- a/src/action/list_indexes.rs +++ b/src/action/list_indexes.rs @@ -1,6 +1,6 @@ use std::{marker::PhantomData, time::Duration}; -use bson::Bson; +use crate::bson::Bson; use futures_util::stream::TryStreamExt; use crate::{ diff --git a/src/action/replace_one.rs b/src/action/replace_one.rs index 98ad8dfa7..06979dce5 100644 --- a/src/action/replace_one.rs +++ b/src/action/replace_one.rs @@ -1,6 +1,6 @@ use std::borrow::Borrow; -use bson::{Bson, Document, RawDocumentBuf}; +use crate::bson::{Bson, Document, RawDocumentBuf}; use serde::Serialize; use crate::{ @@ -31,7 +31,7 @@ impl Collection { ReplaceOne { coll: CollRef::new(self), query, - replacement: bson::to_raw_document_buf(replacement.borrow()).map_err(Into::into), + replacement: crate::bson::to_raw_document_buf(replacement.borrow()).map_err(Into::into), options: None, session: None, } diff --git a/src/action/run_command.rs b/src/action/run_command.rs index 2466356f2..a94a9baed 100644 --- a/src/action/run_command.rs +++ b/src/action/run_command.rs @@ -1,6 +1,6 @@ use std::time::Duration; -use bson::{Bson, Document, RawDocumentBuf}; +use crate::bson::{Bson, Document, RawDocumentBuf}; use crate::{ client::session::TransactionState, @@ -154,7 +154,7 @@ impl crate::sync::Database { #[must_use] pub struct RunCommand<'a> { db: &'a Database, - command: bson::raw::Result, + command: crate::bson::raw::Result, options: Option, session: Option<&'a mut ClientSession>, } @@ -214,7 +214,7 @@ impl<'a> Action for RunCommand<'a> { #[must_use] pub struct RunCursorCommand<'a, Session = ImplicitSession> { db: &'a Database, - command: bson::raw::Result, + command: crate::bson::raw::Result, options: Option, session: Session, } diff --git a/src/action/search_index.rs b/src/action/search_index.rs index 05ef0074a..b3ea37546 100644 --- a/src/action/search_index.rs +++ b/src/action/search_index.rs @@ -1,6 +1,6 @@ use std::marker::PhantomData; -use bson::{doc, Document}; +use crate::bson::{doc, Document}; use super::{ action_impl, diff --git a/src/action/update.rs b/src/action/update.rs index c0c40b0e5..d53bdd590 100644 --- a/src/action/update.rs +++ b/src/action/update.rs @@ -1,4 +1,4 @@ -use bson::{Bson, Document}; +use crate::bson::{Bson, Document}; use crate::{ coll::options::{Hint, UpdateModifications, UpdateOptions}, diff --git a/src/action/watch.rs b/src/action/watch.rs index afbf6d65f..fae772d53 100644 --- a/src/action/watch.rs +++ b/src/action/watch.rs @@ -1,6 +1,6 @@ use std::{marker::PhantomData, time::Duration}; -use bson::{Bson, Document, Timestamp}; +use crate::bson::{Bson, Document, Timestamp}; use serde::de::DeserializeOwned; use super::{ diff --git a/src/bson_util.rs b/src/bson_util.rs index c61e0499a..22095c08a 100644 --- a/src/bson_util.rs +++ b/src/bson_util.rs @@ -84,7 +84,7 @@ pub(crate) fn to_raw_bson_array(docs: &[Document]) -> Result { pub(crate) fn to_raw_bson_array_ser(values: &[T]) -> Result { let mut array = RawArrayBuf::new(); for value in values { - array.push(bson::to_raw_document_buf(value)?); + array.push(crate::bson::to_raw_document_buf(value)?); } Ok(RawBson::Array(array)) } @@ -213,7 +213,7 @@ pub(crate) fn append_ser( struct Helper { value: T, } - let raw_doc = bson::to_raw_document_buf(&Helper { value })?; + let raw_doc = crate::bson::to_raw_document_buf(&Helper { value })?; this.append_ref( key, raw_doc diff --git a/src/change_stream.rs b/src/change_stream.rs index 89da6bde0..8bf21510a 100644 --- a/src/change_stream.rs +++ b/src/change_stream.rs @@ -12,8 +12,8 @@ use std::{ }; #[cfg(test)] -use bson::RawDocumentBuf; -use bson::{Document, Timestamp}; +use crate::bson::RawDocumentBuf; +use crate::bson::{Document, Timestamp}; use derive_where::derive_where; use futures_core::{future::BoxFuture, Stream}; use serde::de::DeserializeOwned; @@ -158,7 +158,7 @@ where /// ``` pub async fn next_if_any(&mut self) -> Result> { Ok(match NextInBatchFuture::new(self).await? { - BatchValue::Some { doc, .. } => Some(bson::from_slice(doc.as_bytes())?), + BatchValue::Some { doc, .. } => Some(crate::bson::from_slice(doc.as_bytes())?), BatchValue::Empty | BatchValue::Exhausted => None, }) } diff --git a/src/change_stream/event.rs b/src/change_stream/event.rs index 0e320c857..0156ccf64 100644 --- a/src/change_stream/event.rs +++ b/src/change_stream/event.rs @@ -5,8 +5,8 @@ use std::convert::TryInto; use crate::{cursor::CursorSpecification, options::ChangeStreamOptions}; #[cfg(test)] -use bson::Bson; -use bson::{DateTime, Document, RawBson, RawDocumentBuf, Timestamp}; +use crate::bson::Bson; +use crate::bson::{DateTime, Document, RawBson, RawDocumentBuf, Timestamp}; use serde::{Deserialize, Serialize}; /// An opaque token used for resuming an interrupted @@ -43,7 +43,7 @@ impl ResumeToken { } #[cfg(test)] - pub(crate) fn parsed(self) -> std::result::Result { + pub(crate) fn parsed(self) -> std::result::Result { self.0.try_into() } } diff --git a/src/change_stream/session.rs b/src/change_stream/session.rs index 0af9e2fa4..f94793271 100644 --- a/src/change_stream/session.rs +++ b/src/change_stream/session.rs @@ -74,8 +74,7 @@ where /// The session provided must be the same session used to create the change stream. /// /// ``` - /// # use bson::{doc, Document}; - /// # use mongodb::Client; + /// # use mongodb::{Client, bson::{self, doc, Document}}; /// # fn main() { /// # async { /// # let client = Client::with_uri_str("foo").await?; @@ -149,7 +148,7 @@ where match bv { BatchValue::Some { doc, .. } => { self.data.document_returned = true; - return Ok(Some(bson::from_slice(doc.as_bytes())?)); + return Ok(Some(crate::bson::from_slice(doc.as_bytes())?)); } BatchValue::Empty | BatchValue::Exhausted => return Ok(None), } diff --git a/src/client.rs b/src/client.rs index 1a4e984af..7f5defc63 100644 --- a/src/client.rs +++ b/src/client.rs @@ -85,9 +85,10 @@ const DEFAULT_SERVER_SELECTION_TIMEOUT: Duration = Duration::from_secs(30); /// way to achieve maximum performance, as the driver is designed to work well in such situations. /// /// Additionally, using a custom Rust type that implements `Serialize` and `Deserialize` as the -/// generic parameter of [`Collection`](../struct.Collection.html) instead of [`bson::Document`] can -/// reduce the amount of time the driver and your application spends serializing and deserializing -/// BSON, which can also lead to increased performance. +/// generic parameter of [`Collection`](../struct.Collection.html) instead of +/// [`Document`](crate::bson::Document) can reduce the amount of time the driver and your +/// application spends serializing and deserializing BSON, which can also lead to increased +/// performance. /// /// ## TCP Keepalive /// TCP keepalive is enabled by default with ``tcp_keepalive_time`` set to 120 seconds. The @@ -194,10 +195,8 @@ impl Client { /// Return an `EncryptedClientBuilder` for constructing a `Client` with auto-encryption enabled. /// /// ```no_run - /// # use bson::doc; /// # use mongocrypt::ctx::KmsProvider; - /// # use mongodb::Client; - /// # use mongodb::error::Result; + /// # use mongodb::{Client, bson::{self, doc}, error::Result}; /// # async fn func() -> Result<()> { /// # let client_options = todo!(); /// # let key_vault_namespace = todo!(); @@ -206,7 +205,7 @@ impl Client { /// let encrypted_client = Client::encrypted_builder( /// client_options, /// key_vault_namespace, - /// [(KmsProvider::Local, doc! { "key": local_key }, None)], + /// [(KmsProvider::local(), doc! { "key": local_key }, None)], /// )? /// .key_vault_client(key_vault_client) /// .build() @@ -221,7 +220,7 @@ impl Client { kms_providers: impl IntoIterator< Item = ( mongocrypt::ctx::KmsProvider, - bson::Document, + crate::bson::Document, Option, ), >, @@ -429,7 +428,7 @@ impl Client { } #[cfg(test)] - pub(crate) async fn is_session_checked_in(&self, id: &bson::Document) -> bool { + pub(crate) async fn is_session_checked_in(&self, id: &crate::bson::Document) -> bool { self.inner.session_pool.contains(id).await } diff --git a/src/client/auth.rs b/src/client/auth.rs index 569d5decd..5f7c9dcb4 100644 --- a/src/client/auth.rs +++ b/src/client/auth.rs @@ -14,7 +14,7 @@ mod x509; use std::{borrow::Cow, fmt::Debug, str::FromStr}; -use bson::RawDocumentBuf; +use crate::bson::RawDocumentBuf; use derive_where::derive_where; use hmac::{digest::KeyInit, Mac}; use rand::Rng; diff --git a/src/client/auth/aws.rs b/src/client/auth/aws.rs index b8a49681c..ea72cbbd3 100644 --- a/src/client/auth/aws.rs +++ b/src/client/auth/aws.rs @@ -167,7 +167,7 @@ pub(crate) struct AwsCredential { default, deserialize_with = "serde_util::deserialize_datetime_option_from_double_or_string" )] - expiration: Option, + expiration: Option, } fn non_empty(s: Option) -> Option { @@ -287,7 +287,7 @@ impl AwsCredential { .map_err(|_| Error::unknown_authentication_error(MECH_NAME))? .to_owned(); - Ok(bson::from_document(credential)?) + Ok(crate::bson::from_document(credential)?) } /// Obtains credentials from the ECS endpoint. @@ -474,7 +474,7 @@ impl AwsCredential { fn is_expired(&self) -> bool { match self.expiration { Some(expiration) => { - expiration.saturating_duration_since(bson::DateTime::now()) + expiration.saturating_duration_since(crate::bson::DateTime::now()) < Duration::from_secs(5 * 60) } None => true, @@ -512,7 +512,7 @@ impl ServerFirst { let ServerFirstPayload { server_nonce, sts_host, - } = bson::from_slice(payload.as_slice()) + } = crate::bson::from_slice(payload.as_slice()) .map_err(|_| Error::invalid_authentication_response(MECH_NAME))?; Ok(Self { @@ -591,11 +591,11 @@ pub(crate) mod test_utils { cached_credential().await.unwrap().session_token } - pub(crate) async fn cached_expiration() -> bson::DateTime { + pub(crate) async fn cached_expiration() -> crate::bson::DateTime { cached_credential().await.unwrap().expiration.unwrap() } - pub(crate) async fn set_cached_expiration(expiration: bson::DateTime) { + pub(crate) async fn set_cached_expiration(expiration: crate::bson::DateTime) { CACHED_CREDENTIAL.lock().await.as_mut().unwrap().expiration = Some(expiration); } } diff --git a/src/client/auth/oidc.rs b/src/client/auth/oidc.rs index 075f1290c..bff78e0b6 100644 --- a/src/client/auth/oidc.rs +++ b/src/client/auth/oidc.rs @@ -8,12 +8,12 @@ use tokio::sync::Mutex; use typed_builder::TypedBuilder; use crate::{ + bson::{doc, rawdoc, spec::BinarySubtype, Binary, Document}, client::options::{ServerAddress, ServerApi}, cmap::{Command, Connection}, error::{Error, Result}, BoxFuture, }; -use bson::{doc, rawdoc, spec::BinarySubtype, Binary, Document}; use super::{ sasl::{SaslContinue, SaslResponse, SaslStart}, @@ -688,7 +688,7 @@ async fn do_two_step_function( } let server_info: IdpServerInfo = - bson::from_slice(&response.payload).map_err(|_| invalid_auth_response())?; + crate::bson::from_slice(&response.payload).map_err(|_| invalid_auth_response())?; let idp_response = { let cb_context = CallbackContext { timeout: Some(Instant::now() + timeout), diff --git a/src/client/auth/sasl.rs b/src/client/auth/sasl.rs index f03fccf40..087134a5f 100644 --- a/src/client/auth/sasl.rs +++ b/src/client/auth/sasl.rs @@ -1,4 +1,4 @@ -use bson::{rawdoc, RawBson}; +use crate::bson::{rawdoc, RawBson}; use crate::{ bson::{spec::BinarySubtype, Binary, Bson, Document}, @@ -104,9 +104,9 @@ fn validate_command_success(auth_mechanism: &str, response: &Document) -> Result match bson_util::get_int(ok) { Some(1) => Ok(()), Some(_) => { - let source = bson::from_bson::>(Bson::Document( - response.clone(), - )) + let source = crate::bson::from_bson::>( + Bson::Document(response.clone()), + ) .map(|cmd_resp| cmd_resp.body.into()) .ok(); Err(Error::authentication_error( diff --git a/src/client/auth/x509.rs b/src/client/auth/x509.rs index 9695070c5..8932a8f71 100644 --- a/src/client/auth/x509.rs +++ b/src/client/auth/x509.rs @@ -1,4 +1,4 @@ -use bson::rawdoc; +use crate::bson::rawdoc; use crate::{ bson::Document, diff --git a/src/client/csfle.rs b/src/client/csfle.rs index d99273895..2cff5632c 100644 --- a/src/client/csfle.rs +++ b/src/client/csfle.rs @@ -102,10 +102,10 @@ impl ClientState { .retry_kms(true)? .use_range_v2()?; if let Some(m) = &opts.schema_map { - builder = builder.schema_map(&bson::to_document(m)?)?; + builder = builder.schema_map(&crate::bson::to_document(m)?)?; } if let Some(m) = &opts.encrypted_fields_map { - builder = builder.encrypted_field_config_map(&bson::to_document(m)?)?; + builder = builder.encrypted_field_config_map(&crate::bson::to_document(m)?)?; } #[cfg(not(test))] let disable_crypt_shared = false; @@ -214,7 +214,7 @@ impl ClientState { pub(crate) fn aux_collections( base_ns: &Namespace, - enc_fields: &bson::Document, + enc_fields: &crate::bson::Document, ) -> Result> { let mut out = vec![]; for &key in &["esc", "ecoc"] { diff --git a/src/client/csfle/client_builder.rs b/src/client/csfle/client_builder.rs index 489a16eaf..2ef163ec0 100644 --- a/src/client/csfle/client_builder.rs +++ b/src/client/csfle/client_builder.rs @@ -7,10 +7,8 @@ use super::options::AutoEncryptionOptions; /// A builder for constructing a `Client` with auto-encryption enabled. /// /// ```no_run -/// # use bson::doc; /// # use mongocrypt::ctx::KmsProvider; -/// # use mongodb::Client; -/// # use mongodb::error::Result; +/// # use mongodb::{Client, bson::{self, doc}, error::Result}; /// # async fn func() -> Result<()> { /// # let client_options = todo!(); /// # let key_vault_namespace = todo!(); @@ -19,7 +17,7 @@ use super::options::AutoEncryptionOptions; /// let encrypted_client = Client::encrypted_builder( /// client_options, /// key_vault_namespace, -/// [(KmsProvider::Local, doc! { "key": local_key }, None)], +/// [(KmsProvider::local(), doc! { "key": local_key }, None)], /// )? /// .key_vault_client(key_vault_client) /// .build() diff --git a/src/client/csfle/client_encryption.rs b/src/client/csfle/client_encryption.rs index 519ccfd3e..40d12283a 100644 --- a/src/client/csfle/client_encryption.rs +++ b/src/client/csfle/client_encryption.rs @@ -39,10 +39,8 @@ impl ClientEncryption { /// Initialize a new `ClientEncryption`. /// /// ```no_run - /// # use bson::doc; /// # use mongocrypt::ctx::KmsProvider; - /// # use mongodb::client_encryption::ClientEncryption; - /// # use mongodb::error::Result; + /// # use mongodb::{bson::doc, client_encryption::ClientEncryption, error::Result}; /// # fn func() -> Result<()> { /// # let kv_client = todo!(); /// # let kv_namespace = todo!(); @@ -51,8 +49,8 @@ impl ClientEncryption { /// kv_client, /// kv_namespace, /// [ - /// (KmsProvider::Local, doc! { "key": local_key }, None), - /// (KmsProvider::Kmip, doc! { "endpoint": "localhost:5698" }, None), + /// (KmsProvider::local(), doc! { "key": local_key }, None), + /// (KmsProvider::kmip(), doc! { "endpoint": "localhost:5698" }, None), /// ] /// )?; /// # Ok(()) @@ -61,7 +59,9 @@ impl ClientEncryption { pub fn new( key_vault_client: Client, key_vault_namespace: Namespace, - kms_providers: impl IntoIterator)>, + kms_providers: impl IntoIterator< + Item = (KmsProvider, crate::bson::Document, Option), + >, ) -> Result { Self::builder(key_vault_client, key_vault_namespace, kms_providers).build() } @@ -70,10 +70,8 @@ impl ClientEncryption { /// [`ClientEncryptionBuilder`] can be chained to set options. /// /// ```no_run - /// # use bson::doc; /// # use mongocrypt::ctx::KmsProvider; - /// # use mongodb::client_encryption::ClientEncryption; - /// # use mongodb::error::Result; + /// # use mongodb::{bson::doc, client_encryption::ClientEncryption, error::Result}; /// # fn func() -> Result<()> { /// # let kv_client = todo!(); /// # let kv_namespace = todo!(); @@ -82,8 +80,8 @@ impl ClientEncryption { /// kv_client, /// kv_namespace, /// [ - /// (KmsProvider::Local, doc! { "key": local_key }, None), - /// (KmsProvider::Kmip, doc! { "endpoint": "localhost:5698" }, None), + /// (KmsProvider::local(), doc! { "key": local_key }, None), + /// (KmsProvider::kmip(), doc! { "endpoint": "localhost:5698" }, None), /// ] /// ) /// .build()?; @@ -93,7 +91,9 @@ impl ClientEncryption { pub fn builder( key_vault_client: Client, key_vault_namespace: Namespace, - kms_providers: impl IntoIterator)>, + kms_providers: impl IntoIterator< + Item = (KmsProvider, crate::bson::Document, Option), + >, ) -> ClientEncryptionBuilder { ClientEncryptionBuilder { key_vault_client, @@ -183,7 +183,7 @@ impl ClientEncryption { /// Decrypts an encrypted value (BSON binary of subtype 6). /// Returns the original BSON value. - pub async fn decrypt(&self, value: RawBinaryRef<'_>) -> Result { + pub async fn decrypt(&self, value: RawBinaryRef<'_>) -> Result { if value.subtype != BinarySubtype::Encrypted { return Err(Error::invalid_argument(format!( "Invalid binary subtype for decrypt: expected {:?}, got {:?}", @@ -208,7 +208,7 @@ impl ClientEncryption { pub struct ClientEncryptionBuilder { key_vault_client: Client, key_vault_namespace: Namespace, - kms_providers: Vec<(KmsProvider, bson::Document, Option)>, + kms_providers: Vec<(KmsProvider, crate::bson::Document, Option)>, key_cache_expiration: Option, } diff --git a/src/client/csfle/client_encryption/create_data_key.rs b/src/client/csfle/client_encryption/create_data_key.rs index 5ecb3da3f..7cb4b7853 100644 --- a/src/client/csfle/client_encryption/create_data_key.rs +++ b/src/client/csfle/client_encryption/create_data_key.rs @@ -1,4 +1,4 @@ -use bson::{doc, Binary}; +use crate::bson::{doc, Binary}; use mongocrypt::ctx::{Ctx, KmsProvider}; use crate::{ @@ -44,7 +44,7 @@ impl ClientEncryption { let mut builder = self.crypt.ctx_builder(); let mut key_doc = doc! { "provider": kms_provider.as_string() }; if !matches!(master_key, MasterKey::Local(_)) { - let master_doc = bson::to_document(&master_key)?; + let master_doc = crate::bson::to_document(&master_key)?; key_doc.extend(master_doc); } if let Some(opts) = opts { diff --git a/src/client/csfle/client_encryption/encrypt.rs b/src/client/csfle/client_encryption/encrypt.rs index 71555308b..98305f010 100644 --- a/src/client/csfle/client_encryption/encrypt.rs +++ b/src/client/csfle/client_encryption/encrypt.rs @@ -1,4 +1,4 @@ -use bson::{Binary, Document}; +use crate::bson::{Binary, Document}; use mongocrypt::ctx::{Algorithm, CtxBuilder}; use crate::{ @@ -86,7 +86,7 @@ impl ClientEncryption { builder = builder.query_type(qtype)?; } if let Some(range_options) = &opts.range_options { - let options_doc = bson::to_document(range_options)?; + let options_doc = crate::bson::to_document(range_options)?; builder = builder.algorithm_range(options_doc)?; } Ok(builder) diff --git a/src/client/csfle/options.rs b/src/client/csfle/options.rs index 56247d945..b4866c0a1 100644 --- a/src/client/csfle/options.rs +++ b/src/client/csfle/options.rs @@ -1,6 +1,6 @@ use std::{collections::HashMap, time::Duration}; -use bson::Array; +use crate::bson::Array; use mongocrypt::ctx::KmsProvider; use serde::Deserialize; @@ -107,7 +107,7 @@ pub(crate) type KmsProvidersTlsOptions = HashMap; impl KmsProviders { pub(crate) fn new( - providers: impl IntoIterator)>, + providers: impl IntoIterator)>, ) -> Result { let mut credentials = HashMap::new(); let mut tls_options = None; @@ -129,7 +129,7 @@ impl KmsProviders { } pub(crate) fn credentials_doc(&self) -> Result { - Ok(bson::to_document(&self.credentials)?) + Ok(crate::bson::to_document(&self.credentials)?) } pub(crate) fn tls_options(&self) -> Option<&KmsProvidersTlsOptions> { diff --git a/src/client/csfle/state_machine.rs b/src/client/csfle/state_machine.rs index ecc81f149..4237002a2 100644 --- a/src/client/csfle/state_machine.rs +++ b/src/client/csfle/state_machine.rs @@ -5,7 +5,7 @@ use std::{ time::Duration, }; -use bson::{rawdoc, Document, RawDocument, RawDocumentBuf}; +use crate::bson::{rawdoc, Document, RawDocument, RawDocumentBuf}; use futures_util::{stream, TryStreamExt}; use mongocrypt::ctx::{Ctx, KmsCtx, KmsProviderType, State}; use rayon::ThreadPool; @@ -452,7 +452,7 @@ fn raw_to_doc(raw: &RawDocument) -> Result { #[cfg(feature = "azure-kms")] pub(crate) mod azure { - use bson::{rawdoc, RawDocumentBuf}; + use crate::bson::{rawdoc, RawDocumentBuf}; use serde::Deserialize; use std::time::{Duration, Instant}; use tokio::sync::Mutex; diff --git a/src/client/executor.rs b/src/client/executor.rs index 87a0f7209..33f9da7c8 100644 --- a/src/client/executor.rs +++ b/src/client/executor.rs @@ -1,6 +1,6 @@ #[cfg(feature = "in-use-encryption")] -use bson::RawDocumentBuf; -use bson::{doc, RawBsonRef, RawDocument, Timestamp}; +use crate::bson::RawDocumentBuf; +use crate::bson::{doc, RawBsonRef, RawDocument, Timestamp}; #[cfg(feature = "in-use-encryption")] use futures_core::future::BoxFuture; use once_cell::sync::Lazy; @@ -835,7 +835,7 @@ impl Client { let cluster_time: Option = raw_doc .get("$clusterTime")? .and_then(RawBsonRef::as_document) - .map(|d| bson::from_slice(d.as_bytes())) + .map(|d| crate::bson::from_slice(d.as_bytes())) .transpose()?; let at_cluster_time = op.extract_at_cluster_time(raw_doc)?; @@ -858,7 +858,7 @@ impl Client { let recovery_token = raw_doc .get("recoveryToken")? .and_then(RawBsonRef::as_document) - .map(|d| bson::from_slice(d.as_bytes())) + .map(|d| crate::bson::from_slice(d.as_bytes())) .transpose()?; session.transaction.recovery_token = recovery_token; } diff --git a/src/client/options.rs b/src/client/options.rs index 6c0aa165a..951245b12 100644 --- a/src/client/options.rs +++ b/src/client/options.rs @@ -17,7 +17,7 @@ use std::{ time::Duration, }; -use bson::UuidRepresentation; +use crate::bson::UuidRepresentation; use derive_where::derive_where; use macro_magic::export_tokens; use once_cell::sync::Lazy; @@ -914,10 +914,10 @@ pub struct ConnectionString { /// Default read preference for the client. pub read_preference: Option, - /// The [`UuidRepresentation`] to use when decoding [`Binary`](bson::Binary) values with the - /// [`UuidOld`](bson::spec::BinarySubtype::UuidOld) subtype. This is not used by the - /// driver; client code can use this when deserializing relevant values with - /// [`Binary::to_uuid_with_representation`](bson::binary::Binary::to_uuid_with_representation). + /// The [`UuidRepresentation`] to use when decoding [`Binary`](crate::bson::Binary) values with + /// the [`UuidOld`](crate::bson::spec::BinarySubtype::UuidOld) subtype. This is not used by + /// the driver; client code can use this when deserializing relevant values with + /// [`Binary::to_uuid_with_representation`](crate::bson::binary::Binary::to_uuid_with_representation). pub uuid_representation: Option, /// Limit on the number of mongos connections that may be created for sharded topologies. diff --git a/src/client/options/bulk_write.rs b/src/client/options/bulk_write.rs index 43d9e87b8..6ede2d219 100644 --- a/src/client/options/bulk_write.rs +++ b/src/client/options/bulk_write.rs @@ -298,7 +298,7 @@ where /// Note that the returned value must be provided to [`bulk_write`](crate::Client::bulk_write) /// for the insert to be performed. pub fn insert_one_model(&self, document: impl Borrow) -> Result { - let document = bson::to_document(document.borrow())?; + let document = crate::bson::to_document(document.borrow())?; Ok(InsertOneModel::builder() .namespace(self.namespace()) .document(document) @@ -315,7 +315,7 @@ where filter: Document, replacement: impl Borrow, ) -> Result { - let replacement = bson::to_document(replacement.borrow())?; + let replacement = crate::bson::to_document(replacement.borrow())?; Ok(ReplaceOneModel::builder() .namespace(self.namespace()) .filter(filter) @@ -388,7 +388,7 @@ impl WriteModel { (rawdoc! { "document": insert_document }, Some(inserted_id)) } _ => { - let model_document = bson::to_raw_document_buf(&self)?; + let model_document = crate::bson::to_raw_document_buf(&self)?; (model_document, None) } }; diff --git a/src/client/options/test.rs b/src/client/options/test.rs index 3df1a9613..989d3ba54 100644 --- a/src/client/options/test.rs +++ b/src/client/options/test.rs @@ -1,6 +1,6 @@ use std::time::Duration; -use bson::UuidRepresentation; +use crate::bson::UuidRepresentation; use once_cell::sync::Lazy; use pretty_assertions::assert_eq; use serde::Deserialize; @@ -122,7 +122,7 @@ async fn run_tests(path: &[&str], skipped_files: &[&str]) { } let mut actual_options = - bson::to_document(&client_options).expect(&test_case.description); + crate::bson::to_document(&client_options).expect(&test_case.description); if let Some(mode) = actual_options.remove("mode") { actual_options.insert("readPreference", mode); @@ -381,7 +381,7 @@ fn unix_domain_socket_not_allowed() { async fn tls_cert_key_password_connect() { use std::path::PathBuf; - use bson::doc; + use crate::bson::doc; use crate::{ options::TlsOptions, diff --git a/src/client/session/test.rs b/src/client/session/test.rs index 9f290a584..94024077c 100644 --- a/src/client/session/test.rs +++ b/src/client/session/test.rs @@ -2,7 +2,7 @@ mod causal_consistency; use std::{future::Future, sync::Arc, time::Duration}; -use bson::Document; +use crate::bson::Document; use futures::stream::StreamExt; use crate::{ @@ -54,7 +54,7 @@ macro_rules! collection_op { |client| async move { let $coll = client .database($test_name) - .collection::($test_name); + .collection::($test_name); $body.await.unwrap(); } }; diff --git a/src/client/session/test/causal_consistency.rs b/src/client/session/test/causal_consistency.rs index 51145d639..6778a2cf0 100644 --- a/src/client/session/test/causal_consistency.rs +++ b/src/client/session/test/causal_consistency.rs @@ -1,4 +1,4 @@ -use bson::{doc, Document}; +use crate::bson::{doc, Document}; use futures::{future::BoxFuture, FutureExt}; use crate::{ diff --git a/src/cmap/conn/command.rs b/src/cmap/conn/command.rs index 37e0fa246..262706f10 100644 --- a/src/cmap/conn/command.rs +++ b/src/cmap/conn/command.rs @@ -1,4 +1,4 @@ -use bson::{RawDocument, RawDocumentBuf}; +use crate::bson::{RawDocument, RawDocumentBuf}; use serde::{de::DeserializeOwned, Deserialize, Serialize}; use super::wire::{message::DocumentSequence, Message}; @@ -202,7 +202,7 @@ impl RawCommandResponse { } pub(crate) fn body<'a, T: Deserialize<'a>>(&'a self) -> Result { - bson::from_slice(self.raw.as_bytes()).map_err(|e| { + crate::bson::from_slice(self.raw.as_bytes()).map_err(|e| { Error::from(ErrorKind::InvalidResponse { message: format!("{}", e), }) @@ -212,7 +212,7 @@ impl RawCommandResponse { /// Used to handle decoding responses where the server may return invalid UTF-8 in error /// messages. pub(crate) fn body_utf8_lossy<'a, T: Deserialize<'a>>(&'a self) -> Result { - bson::from_slice_utf8_lossy(self.raw.as_bytes()).map_err(|e| { + crate::bson::from_slice_utf8_lossy(self.raw.as_bytes()).map_err(|e| { Error::from(ErrorKind::InvalidResponse { message: format!("{}", e), }) diff --git a/src/cmap/conn/stream_description.rs b/src/cmap/conn/stream_description.rs index a12a7f2f6..b6c6ca05f 100644 --- a/src/cmap/conn/stream_description.rs +++ b/src/cmap/conn/stream_description.rs @@ -1,6 +1,6 @@ use std::time::Duration; -use bson::oid::ObjectId; +use crate::bson::oid::ObjectId; use crate::{client::options::ServerAddress, hello::HelloReply, sdam::ServerType}; diff --git a/src/cmap/conn/wire/message.rs b/src/cmap/conn/wire/message.rs index fcece7a1f..a4b0fd93f 100644 --- a/src/cmap/conn/wire/message.rs +++ b/src/cmap/conn/wire/message.rs @@ -1,7 +1,7 @@ use std::io::Read; +use crate::bson::{doc, Array, Document}; use bitflags::bitflags; -use bson::{doc, Array, Document}; use tokio::io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt}; #[cfg(any( @@ -62,7 +62,7 @@ impl TryFrom for Message { type Error = Error; fn try_from(command: Command) -> Result { - let document_payload = bson::to_raw_document_buf(&command)?; + let document_payload = crate::bson::to_raw_document_buf(&command)?; #[cfg(any( feature = "zstd-compression", feature = "zlib-compression", diff --git a/src/cmap/establish/handshake.rs b/src/cmap/establish/handshake.rs index 15b0acb2f..f8b100694 100644 --- a/src/cmap/establish/handshake.rs +++ b/src/cmap/establish/handshake.rs @@ -3,7 +3,7 @@ mod test; use std::env; -use bson::{rawdoc, RawBson, RawDocumentBuf}; +use crate::bson::{rawdoc, RawBson, RawDocumentBuf}; use once_cell::sync::Lazy; use tokio::sync::broadcast; @@ -388,7 +388,7 @@ impl Handshaker { compressors .iter() .map(|compressor| compressor.name()) - .collect::(), + .collect::(), ); } diff --git a/src/cmap/establish/handshake/test.rs b/src/cmap/establish/handshake/test.rs index d5d1c0dec..f9c4ee00f 100644 --- a/src/cmap/establish/handshake/test.rs +++ b/src/cmap/establish/handshake/test.rs @@ -1,6 +1,6 @@ use std::ops::Deref; -use bson::rawdoc; +use crate::bson::rawdoc; use super::Handshaker; use crate::{cmap::establish::handshake::HandshakerOptions, options::DriverInfo}; diff --git a/src/cmap/test.rs b/src/cmap/test.rs index 8f86698df..94d575c4d 100644 --- a/src/cmap/test.rs +++ b/src/cmap/test.rs @@ -167,7 +167,7 @@ impl Executor { )) .unwrap(), updater, - bson::oid::ObjectId::new(), + crate::bson::oid::ObjectId::new(), Some(self.pool_options), ); diff --git a/src/cmap/test/integration.rs b/src/cmap/test/integration.rs index 1d0178bbe..2c3c0c2c4 100644 --- a/src/cmap/test/integration.rs +++ b/src/cmap/test/integration.rs @@ -1,4 +1,4 @@ -use bson::rawdoc; +use crate::bson::rawdoc; use serde::Deserialize; use super::EVENT_TIMEOUT; @@ -52,7 +52,7 @@ async fn acquire_connection_and_send_command() { ConnectionEstablisher::new(EstablisherOptions::from_client_options(&client_options)) .unwrap(), TopologyUpdater::channel().0, - bson::oid::ObjectId::new(), + crate::bson::oid::ObjectId::new(), Some(pool_options), ); let mut connection = pool.check_out().await.unwrap(); @@ -72,7 +72,7 @@ async fn acquire_connection_and_send_command() { assert!(doc_response.is_success()); - let response: ListDatabasesResponse = bson::from_document(doc_response.body).unwrap(); + let response: ListDatabasesResponse = crate::bson::from_document(doc_response.body).unwrap(); let names: Vec<_> = response .databases @@ -126,7 +126,7 @@ async fn concurrent_connections() { ConnectionEstablisher::new(EstablisherOptions::from_client_options(&client_options)) .unwrap(), TopologyUpdater::channel().0, - bson::oid::ObjectId::new(), + crate::bson::oid::ObjectId::new(), Some(options), ); @@ -211,7 +211,7 @@ async fn connection_error_during_establishment() { ConnectionEstablisher::new(EstablisherOptions::from_client_options(&client_options)) .unwrap(), TopologyUpdater::channel().0, - bson::oid::ObjectId::new(), + crate::bson::oid::ObjectId::new(), Some(options), ); diff --git a/src/coll.rs b/src/coll.rs index 362f48e48..ff579d0c5 100644 --- a/src/coll.rs +++ b/src/coll.rs @@ -3,7 +3,7 @@ pub mod options; use std::{fmt, fmt::Debug, str::FromStr, sync::Arc}; -use bson::rawdoc; +use crate::bson::rawdoc; use serde::{de::Error as DeError, Deserialize, Deserializer, Serialize}; use self::options::*; diff --git a/src/coll/action/drop.rs b/src/coll/action/drop.rs index ebbc38a8e..3a845550b 100644 --- a/src/coll/action/drop.rs +++ b/src/coll/action/drop.rs @@ -35,7 +35,7 @@ where options: Option<&crate::coll::DropCollectionOptions>, mut session: Option<&mut crate::ClientSession>, ) -> Result<()> { - use bson::doc; + use crate::bson::doc; use futures_util::TryStreamExt; // Find associated `encrypted_fields`: diff --git a/src/concern/test.rs b/src/concern/test.rs index ca45321f0..f342b1416 100644 --- a/src/concern/test.rs +++ b/src/concern/test.rs @@ -45,7 +45,7 @@ fn write_concern_is_acknowledged() { #[test] fn write_concern_deserialize() { let w_1 = doc! { "w": 1 }; - let wc: WriteConcern = bson::from_bson(Bson::Document(w_1)).unwrap(); + let wc: WriteConcern = crate::bson::from_bson(Bson::Document(w_1)).unwrap(); assert_eq!( wc, WriteConcern { @@ -56,7 +56,7 @@ fn write_concern_deserialize() { ); let w_majority = doc! { "w": "majority" }; - let wc: WriteConcern = bson::from_bson(Bson::Document(w_majority)).unwrap(); + let wc: WriteConcern = crate::bson::from_bson(Bson::Document(w_majority)).unwrap(); assert_eq!( wc, WriteConcern { @@ -67,7 +67,7 @@ fn write_concern_deserialize() { ); let w_timeout = doc! { "w": "majority", "wtimeout": 100 }; - let wc: WriteConcern = bson::from_bson(Bson::Document(w_timeout)).unwrap(); + let wc: WriteConcern = crate::bson::from_bson(Bson::Document(w_timeout)).unwrap(); assert_eq!( wc, WriteConcern { @@ -78,7 +78,7 @@ fn write_concern_deserialize() { ); let journal = doc! { "w": "majority", "j": true }; - let wc: WriteConcern = bson::from_bson(Bson::Document(journal)).unwrap(); + let wc: WriteConcern = crate::bson::from_bson(Bson::Document(journal)).unwrap(); assert_eq!( wc, WriteConcern { diff --git a/src/cursor.rs b/src/cursor.rs index b40a8b56b..d8dd1c004 100644 --- a/src/cursor.rs +++ b/src/cursor.rs @@ -8,10 +8,10 @@ use std::{ task::{Context, Poll}, }; -use bson::RawDocument; +use crate::bson::RawDocument; #[cfg(test)] -use bson::RawDocumentBuf; +use crate::bson::RawDocumentBuf; use derive_where::derive_where; use futures_core::Stream; use serde::{de::DeserializeOwned, Deserialize}; @@ -272,7 +272,7 @@ impl Cursor { where T: Deserialize<'a>, { - bson::from_slice(self.current().as_bytes()).map_err(Error::from) + crate::bson::from_slice(self.current().as_bytes()).map_err(Error::from) } /// Update the type streamed values will be parsed as. diff --git a/src/cursor/common.rs b/src/cursor/common.rs index 26c52a8ca..342c4a6aa 100644 --- a/src/cursor/common.rs +++ b/src/cursor/common.rs @@ -5,7 +5,7 @@ use std::{ time::Duration, }; -use bson::{RawDocument, RawDocumentBuf}; +use crate::bson::{RawDocument, RawDocumentBuf}; use derive_where::derive_where; use futures_core::{future::BoxFuture, Future}; #[cfg(test)] @@ -277,7 +277,7 @@ where Poll::Pending => return Poll::Pending, Poll::Ready(bv) => match bv? { BatchValue::Some { doc, .. } => { - return Poll::Ready(Some(Ok(bson::from_slice(doc.as_bytes())?))) + return Poll::Ready(Some(Ok(crate::bson::from_slice(doc.as_bytes())?))) } BatchValue::Empty => continue, BatchValue::Exhausted => return Poll::Ready(None), @@ -589,7 +589,7 @@ impl AsRef> for CursorBuffer { #[test] fn test_buffer() { - use bson::rawdoc; + use crate::bson::rawdoc; let queue: VecDeque = [rawdoc! { "x": 1 }, rawdoc! { "x": 2 }, rawdoc! { "x": 3 }].into(); diff --git a/src/cursor/session.rs b/src/cursor/session.rs index d4f696e2a..78f69275b 100644 --- a/src/cursor/session.rs +++ b/src/cursor/session.rs @@ -4,7 +4,7 @@ use std::{ task::{Context, Poll}, }; -use bson::RawDocument; +use crate::bson::RawDocument; use futures_core::Stream; use futures_util::StreamExt; use serde::{de::DeserializeOwned, Deserialize}; @@ -117,8 +117,7 @@ where /// the stream before using the session. /// /// ``` - /// # use bson::{doc, Document}; - /// # use mongodb::{Client, error::Result}; + /// # use mongodb::{Client, bson::{doc, Document}, error::Result}; /// # fn main() { /// # async { /// # let client = Client::with_uri_str("foo").await?; @@ -165,8 +164,7 @@ where /// functionality of `Stream` is not needed. /// /// ``` - /// # use bson::{doc, Document}; - /// # use mongodb::Client; + /// # use mongodb::{Client, bson::{doc, Document}}; /// # fn main() { /// # async { /// # let client = Client::with_uri_str("foo").await?; @@ -306,7 +304,7 @@ impl SessionCursor { where T: Deserialize<'a>, { - bson::from_slice(self.current().as_bytes()).map_err(Error::from) + crate::bson::from_slice(self.current().as_bytes()).map_err(Error::from) } /// Update the type streamed values will be parsed as. diff --git a/src/db/action/create_collection.rs b/src/db/action/create_collection.rs index e7ff40fc5..769896c33 100644 --- a/src/db/action/create_collection.rs +++ b/src/db/action/create_collection.rs @@ -40,8 +40,10 @@ impl<'a> Action for CreateCollection<'a> { #[cfg(feature = "in-use-encryption")] if has_encrypted_fields { - use crate::action::Action; - use bson::{doc, Document}; + use crate::{ + action::Action, + bson::{doc, Document}, + }; let coll = self.db.collection::(&ns.coll); coll.create_index(crate::IndexModel { keys: doc! {"__safeContent__": 1}, @@ -90,8 +92,7 @@ impl Database { options: &Option, mut session: Option<&mut crate::ClientSession>, ) -> Result<()> { - use crate::error::ErrorKind; - use bson::doc; + use crate::{bson::doc, error::ErrorKind}; let opts = match options { Some(o) => o, diff --git a/src/db/options.rs b/src/db/options.rs index 9679d4a1b..b1f94119b 100644 --- a/src/db/options.rs +++ b/src/db/options.rs @@ -1,6 +1,6 @@ use std::time::Duration; -use bson::doc; +use crate::bson::doc; use macro_magic::export_tokens; use serde::{Deserialize, Serialize}; use serde_with::skip_serializing_none; diff --git a/src/error.rs b/src/error.rs index effb28369..a7439595b 100644 --- a/src/error.rs +++ b/src/error.rs @@ -548,20 +548,20 @@ where } } -impl From for ErrorKind { - fn from(err: bson::de::Error) -> Self { +impl From for ErrorKind { + fn from(err: crate::bson::de::Error) -> Self { Self::BsonDeserialization(err) } } -impl From for ErrorKind { - fn from(err: bson::ser::Error) -> Self { +impl From for ErrorKind { + fn from(err: crate::bson::ser::Error) -> Self { Self::BsonSerialization(err) } } -impl From for ErrorKind { - fn from(err: bson::raw::Error) -> Self { +impl From for ErrorKind { + fn from(err: crate::bson::raw::Error) -> Self { Self::InvalidResponse { message: err.to_string(), } diff --git a/src/gridfs.rs b/src/gridfs.rs index 5d343270f..03ae0e778 100644 --- a/src/gridfs.rs +++ b/src/gridfs.rs @@ -31,7 +31,7 @@ pub(crate) struct Chunk<'a> { #[serde(rename = "_id")] id: ObjectId, files_id: Bson, - #[serde(serialize_with = "bson::serde_helpers::serialize_u32_as_i32")] + #[serde(serialize_with = "crate::bson::serde_helpers::serialize_u32_as_i32")] n: u32, #[serde(borrow)] data: RawBinaryRef<'a>, @@ -54,7 +54,7 @@ pub struct FilesCollectionDocument { /// The size of the file's chunks in bytes. #[serde( rename = "chunkSize", - serialize_with = "bson::serde_helpers::serialize_u32_as_i32" + serialize_with = "crate::bson::serde_helpers::serialize_u32_as_i32" )] pub chunk_size_bytes: u32, diff --git a/src/hello.rs b/src/hello.rs index c11bccf82..63de1d9c8 100644 --- a/src/hello.rs +++ b/src/hello.rs @@ -1,6 +1,6 @@ use std::time::Duration; -use bson::{rawdoc, RawDocumentBuf}; +use crate::bson::{rawdoc, RawDocumentBuf}; use serde::{Deserialize, Serialize}; use tokio::sync::broadcast; diff --git a/src/index.rs b/src/index.rs index 5b21dd257..5cb032e1f 100644 --- a/src/index.rs +++ b/src/index.rs @@ -32,8 +32,8 @@ impl IndexModel { .and_then(|o| o.name.as_ref()) .is_none() { - fn format_kv(kv: (&String, &bson::Bson)) -> String { - if let bson::Bson::String(s) = kv.1 { + fn format_kv(kv: (&String, &crate::bson::Bson)) -> String { + if let crate::bson::Bson::String(s) = kv.1 { format!("{}_{}", kv.0, s) } else { format!("{}_{}", kv.0, kv.1) diff --git a/src/lib.rs b/src/lib.rs index 560bdb22d..0b1ab02d0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -17,7 +17,6 @@ #[macro_use] pub mod options; -pub use ::bson; #[cfg(feature = "in-use-encryption")] pub use ::mongocrypt; @@ -55,6 +54,15 @@ mod test; mod trace; pub(crate) mod tracking_arc; +#[cfg(not(any(feature = "bson-2", feature = "bson-3")))] +compile_error!("One of the bson-2 and bson-3 features must be enabled."); + +#[cfg(all(feature = "bson-2", not(feature = "bson-3")))] +pub use bson2 as bson; + +#[cfg(feature = "bson-3")] +pub use bson3 as bson; + #[cfg(feature = "in-use-encryption")] pub use crate::client::csfle::client_encryption; pub use crate::{ @@ -76,8 +84,8 @@ pub use search_index::{SearchIndexModel, SearchIndexType}; /// A boxed future. pub type BoxFuture<'a, T> = std::pin::Pin + Send + 'a>>; -#[cfg(not(feature = "compat-3-0-0"))] +#[cfg(not(feature = "compat-3-3-0"))] compile_error!( - "The feature 'compat-3-0-0' must be enabled to ensure forward compatibility with future \ + "The feature 'compat-3-3-0' must be enabled to ensure forward compatibility with future \ versions of this crate." ); diff --git a/src/operation/abort_transaction.rs b/src/operation/abort_transaction.rs index a114073c2..a09c8a5a6 100644 --- a/src/operation/abort_transaction.rs +++ b/src/operation/abort_transaction.rs @@ -1,4 +1,4 @@ -use bson::rawdoc; +use crate::bson::rawdoc; use crate::{ bson_util::append_ser, diff --git a/src/operation/aggregate.rs b/src/operation/aggregate.rs index 17b0277d8..dd31e8532 100644 --- a/src/operation/aggregate.rs +++ b/src/operation/aggregate.rs @@ -74,8 +74,8 @@ impl OperationWithDefaults for Aggregate { fn extract_at_cluster_time( &self, - response: &bson::RawDocument, - ) -> Result> { + response: &crate::bson::RawDocument, + ) -> Result> { CursorBody::extract_at_cluster_time(response) } diff --git a/src/operation/aggregate/change_stream.rs b/src/operation/aggregate/change_stream.rs index 4cb67cb85..0b1cb16ef 100644 --- a/src/operation/aggregate/change_stream.rs +++ b/src/operation/aggregate/change_stream.rs @@ -76,8 +76,8 @@ impl OperationWithDefaults for ChangeStreamAggregate { fn extract_at_cluster_time( &self, - response: &bson::RawDocument, - ) -> Result> { + response: &crate::bson::RawDocument, + ) -> Result> { self.inner.extract_at_cluster_time(response) } @@ -89,7 +89,7 @@ impl OperationWithDefaults for ChangeStreamAggregate { let op_time = response .raw_body() .get("operationTime")? - .and_then(bson::RawBsonRef::as_timestamp); + .and_then(crate::bson::RawBsonRef::as_timestamp); let inner_context = ExecutionContext { connection: context.connection, diff --git a/src/operation/bulk_write.rs b/src/operation/bulk_write.rs index 2b5c9c9ed..62761fcd4 100644 --- a/src/operation/bulk_write.rs +++ b/src/operation/bulk_write.rs @@ -93,7 +93,7 @@ where loop { for response_document in &responses { let response: SingleOperationResponse = - bson::from_slice(response_document.as_bytes())?; + crate::bson::from_slice(response_document.as_bytes())?; self.handle_individual_response(response, result, error)?; } @@ -278,8 +278,8 @@ where let mut command_body = rawdoc! { Self::NAME: 1 }; let mut options = match self.options { - Some(options) => bson::to_raw_document_buf(options), - None => bson::to_raw_document_buf(&BulkWriteOptions::default()), + Some(options) => crate::bson::to_raw_document_buf(options), + None => crate::bson::to_raw_document_buf(&BulkWriteOptions::default()), }?; options.append("errorsOnly", R::errors_only()); bson_util::extend_raw_document_buf(&mut command_body, options)?; diff --git a/src/operation/commit_transaction.rs b/src/operation/commit_transaction.rs index eea4042f2..81c931b6b 100644 --- a/src/operation/commit_transaction.rs +++ b/src/operation/commit_transaction.rs @@ -1,6 +1,6 @@ use std::time::Duration; -use bson::rawdoc; +use crate::bson::rawdoc; use crate::{ cmap::{Command, RawCommandResponse, StreamDescription}, diff --git a/src/operation/count.rs b/src/operation/count.rs index 61bb20110..594785eef 100644 --- a/src/operation/count.rs +++ b/src/operation/count.rs @@ -1,4 +1,4 @@ -use bson::rawdoc; +use crate::bson::rawdoc; use serde::Deserialize; use crate::{ diff --git a/src/operation/count_documents.rs b/src/operation/count_documents.rs index 3c9f32ab5..087608b58 100644 --- a/src/operation/count_documents.rs +++ b/src/operation/count_documents.rs @@ -83,7 +83,10 @@ impl OperationWithDefaults for CountDocuments { self.aggregate.build(description) } - fn extract_at_cluster_time(&self, response: &RawDocument) -> Result> { + fn extract_at_cluster_time( + &self, + response: &RawDocument, + ) -> Result> { self.aggregate.extract_at_cluster_time(response) } diff --git a/src/operation/create.rs b/src/operation/create.rs index 681f40233..ea1ab4d0e 100644 --- a/src/operation/create.rs +++ b/src/operation/create.rs @@ -1,4 +1,4 @@ -use bson::rawdoc; +use crate::bson::rawdoc; use crate::{ cmap::{Command, RawCommandResponse, StreamDescription}, diff --git a/src/operation/create_indexes.rs b/src/operation/create_indexes.rs index 8441933ba..f188a2a4c 100644 --- a/src/operation/create_indexes.rs +++ b/src/operation/create_indexes.rs @@ -1,4 +1,4 @@ -use bson::rawdoc; +use crate::bson::rawdoc; use crate::{ bson_util::to_raw_bson_array_ser, diff --git a/src/operation/delete.rs b/src/operation/delete.rs index c74217c54..bbbd9260f 100644 --- a/src/operation/delete.rs +++ b/src/operation/delete.rs @@ -57,11 +57,11 @@ impl OperationWithDefaults for Delete { }; if let Some(ref collation) = self.collation { - delete.insert("collation", bson::to_bson(&collation)?); + delete.insert("collation", crate::bson::to_bson(&collation)?); } if let Some(ref hint) = self.hint { - delete.insert("hint", bson::to_bson(&hint)?); + delete.insert("hint", crate::bson::to_bson(&hint)?); } let mut body = doc! { diff --git a/src/operation/distinct.rs b/src/operation/distinct.rs index cb6362648..3f732c3da 100644 --- a/src/operation/distinct.rs +++ b/src/operation/distinct.rs @@ -58,8 +58,8 @@ impl OperationWithDefaults for Distinct { fn extract_at_cluster_time( &self, - response: &bson::RawDocument, - ) -> Result> { + response: &crate::bson::RawDocument, + ) -> Result> { Ok(response .get("atClusterTime")? .and_then(RawBsonRef::as_timestamp)) diff --git a/src/operation/drop_collection.rs b/src/operation/drop_collection.rs index 98f64b4bb..b565542bb 100644 --- a/src/operation/drop_collection.rs +++ b/src/operation/drop_collection.rs @@ -1,4 +1,4 @@ -use bson::rawdoc; +use crate::bson::rawdoc; use crate::{ cmap::{Command, RawCommandResponse, StreamDescription}, diff --git a/src/operation/drop_database.rs b/src/operation/drop_database.rs index 747c990b7..80b7aa3ae 100644 --- a/src/operation/drop_database.rs +++ b/src/operation/drop_database.rs @@ -1,4 +1,4 @@ -use bson::rawdoc; +use crate::bson::rawdoc; use crate::{ cmap::{Command, RawCommandResponse, StreamDescription}, diff --git a/src/operation/drop_indexes.rs b/src/operation/drop_indexes.rs index 0d706dd19..feda1df37 100644 --- a/src/operation/drop_indexes.rs +++ b/src/operation/drop_indexes.rs @@ -1,4 +1,4 @@ -use bson::rawdoc; +use crate::bson::rawdoc; use crate::{ cmap::{Command, RawCommandResponse, StreamDescription}, diff --git a/src/operation/find.rs b/src/operation/find.rs index d9692c1f7..ae049a032 100644 --- a/src/operation/find.rs +++ b/src/operation/find.rs @@ -1,4 +1,4 @@ -use bson::RawDocumentBuf; +use crate::bson::RawDocumentBuf; use crate::{ bson::{rawdoc, Document}, @@ -84,8 +84,8 @@ impl OperationWithDefaults for Find { fn extract_at_cluster_time( &self, - response: &bson::RawDocument, - ) -> Result> { + response: &crate::bson::RawDocument, + ) -> Result> { CursorBody::extract_at_cluster_time(response) } diff --git a/src/operation/get_more.rs b/src/operation/get_more.rs index fc147fb86..b0deac27b 100644 --- a/src/operation/get_more.rs +++ b/src/operation/get_more.rs @@ -1,6 +1,6 @@ use std::{collections::VecDeque, time::Duration}; -use bson::{rawdoc, RawBson}; +use crate::bson::{rawdoc, RawBson}; use serde::Deserialize; use crate::{ diff --git a/src/operation/insert.rs b/src/operation/insert.rs index 561c871f0..fd76cd4d5 100644 --- a/src/operation/insert.rs +++ b/src/operation/insert.rs @@ -64,7 +64,7 @@ impl OperationWithDefaults for Insert<'_> { let max_operations: usize = Checked::new(description.max_write_batch_size).try_into()?; let mut command_body = rawdoc! { Self::NAME: self.ns.coll.clone() }; - let options = bson::to_raw_document_buf(&self.options)?; + let options = crate::bson::to_raw_document_buf(&self.options)?; extend_raw_document_buf(&mut command_body, options)?; let max_document_sequence_size: usize = (Checked::new(max_message_size) @@ -75,7 +75,7 @@ impl OperationWithDefaults for Insert<'_> { let mut docs = Vec::new(); let mut current_size = Checked::new(0); for (i, document) in self.documents.iter().take(max_operations).enumerate() { - let mut document = bson::to_raw_document_buf(document)?; + let mut document = crate::bson::to_raw_document_buf(document)?; let id = get_or_prepend_id_field(&mut document)?; let doc_size = document.as_bytes().len(); @@ -114,7 +114,7 @@ impl OperationWithDefaults for Insert<'_> { Self::NAME: self.ns.coll.clone(), }; - let options_doc = bson::to_raw_document_buf(&self.options)?; + let options_doc = crate::bson::to_raw_document_buf(&self.options)?; extend_raw_document_buf(&mut body, options_doc)?; if self.encrypted { diff --git a/src/operation/list_collections.rs b/src/operation/list_collections.rs index 5e3e11b9b..d2c0bfa81 100644 --- a/src/operation/list_collections.rs +++ b/src/operation/list_collections.rs @@ -1,4 +1,4 @@ -use bson::rawdoc; +use crate::bson::rawdoc; use crate::{ cmap::{Command, RawCommandResponse, StreamDescription}, diff --git a/src/operation/list_databases.rs b/src/operation/list_databases.rs index 132d76969..8510b42ab 100644 --- a/src/operation/list_databases.rs +++ b/src/operation/list_databases.rs @@ -1,4 +1,4 @@ -use bson::rawdoc; +use crate::bson::rawdoc; use serde::Deserialize; use crate::{ diff --git a/src/operation/list_indexes.rs b/src/operation/list_indexes.rs index 73e330f2a..452024a12 100644 --- a/src/operation/list_indexes.rs +++ b/src/operation/list_indexes.rs @@ -1,4 +1,4 @@ -use bson::rawdoc; +use crate::bson::rawdoc; use crate::{ checked::Checked, diff --git a/src/operation/raw_output.rs b/src/operation/raw_output.rs index b3ece677e..8d90f3170 100644 --- a/src/operation/raw_output.rs +++ b/src/operation/raw_output.rs @@ -23,8 +23,8 @@ impl Operation for RawOutput { fn extract_at_cluster_time( &self, - response: &bson::RawDocument, - ) -> Result> { + response: &crate::bson::RawDocument, + ) -> Result> { self.0.extract_at_cluster_time(response) } diff --git a/src/operation/run_command.rs b/src/operation/run_command.rs index a2f5edf3f..4ad7c050a 100644 --- a/src/operation/run_command.rs +++ b/src/operation/run_command.rs @@ -65,8 +65,8 @@ impl OperationWithDefaults for RunCommand<'_> { fn extract_at_cluster_time( &self, - response: &bson::RawDocument, - ) -> Result> { + response: &crate::bson::RawDocument, + ) -> Result> { if let Some(RawBsonRef::Timestamp(ts)) = response.get("atClusterTime")? { Ok(Some(ts)) } else { diff --git a/src/operation/run_cursor_command.rs b/src/operation/run_cursor_command.rs index 781d84d7e..d535c04b0 100644 --- a/src/operation/run_cursor_command.rs +++ b/src/operation/run_cursor_command.rs @@ -42,8 +42,8 @@ impl Operation for RunCursorCommand<'_> { fn extract_at_cluster_time( &self, - response: &bson::RawDocument, - ) -> Result> { + response: &crate::bson::RawDocument, + ) -> Result> { self.run_command.extract_at_cluster_time(response) } diff --git a/src/operation/search_index.rs b/src/operation/search_index.rs index 7371531d0..784460339 100644 --- a/src/operation/search_index.rs +++ b/src/operation/search_index.rs @@ -1,4 +1,4 @@ -use bson::{rawdoc, RawDocumentBuf}; +use crate::bson::{rawdoc, RawDocumentBuf}; use serde::Deserialize; use crate::{ diff --git a/src/operation/update.rs b/src/operation/update.rs index cb8563ea7..46e05971b 100644 --- a/src/operation/update.rs +++ b/src/operation/update.rs @@ -120,7 +120,7 @@ impl OperationWithDefaults for Update { } if let Some(ref collation) = options.collation { - update.append("collation", bson::to_raw_document_buf(&collation)?); + update.append("collation", crate::bson::to_raw_document_buf(&collation)?); } if let Some(bypass_doc_validation) = options.bypass_document_validation { @@ -129,12 +129,15 @@ impl OperationWithDefaults for Update { if let Some(ref write_concern) = options.write_concern { if !write_concern.is_empty() { - body.append("writeConcern", bson::to_raw_document_buf(write_concern)?); + body.append( + "writeConcern", + crate::bson::to_raw_document_buf(write_concern)?, + ); } } if let Some(ref let_vars) = options.let_vars { - body.append("let", bson::to_raw_document_buf(&let_vars)?); + body.append("let", crate::bson::to_raw_document_buf(&let_vars)?); } if let Some(ref comment) = options.comment { diff --git a/src/sdam/description/server.rs b/src/sdam/description/server.rs index 40a1502dc..e7d2d2aab 100644 --- a/src/sdam/description/server.rs +++ b/src/sdam/description/server.rs @@ -1,6 +1,6 @@ use std::time::Duration; -use bson::{bson, rawdoc, Bson, RawBson}; +use crate::bson::{bson, rawdoc, Bson, RawBson}; use serde::{Deserialize, Serialize}; use crate::{ diff --git a/src/sdam/description/topology/server_selection/test/in_window.rs b/src/sdam/description/topology/server_selection/test/in_window.rs index fe5cbd26d..af7dc0ac1 100644 --- a/src/sdam/description/topology/server_selection/test/in_window.rs +++ b/src/sdam/description/topology/server_selection/test/in_window.rs @@ -1,7 +1,7 @@ use std::{collections::HashMap, sync::Arc, time::Duration}; +use crate::bson::{doc, Document}; use approx::abs_diff_eq; -use bson::{doc, Document}; use serde::Deserialize; use crate::{ diff --git a/src/sdam/description/topology/test/sdam.rs b/src/sdam/description/topology/test/sdam.rs index c5f0dbd51..8c0986d1b 100644 --- a/src/sdam/description/topology/test/sdam.rs +++ b/src/sdam/description/topology/test/sdam.rs @@ -1,6 +1,6 @@ use std::{collections::HashMap, sync::Arc, time::Duration}; -use bson::Document; +use crate::bson::Document; use serde::Deserialize; use super::TestSdamEvent; @@ -754,7 +754,7 @@ async fn pool_cleared_error_does_not_mark_unknown() { // get the one server in the topology let server = topology.servers().into_values().next().unwrap(); - let heartbeat_response: HelloCommandResponse = bson::from_document(doc! { + let heartbeat_response: HelloCommandResponse = crate::bson::from_document(doc! { "ok": 1, "isWritablePrimary": true, "minWireVersion": 0, diff --git a/src/sdam/monitor.rs b/src/sdam/monitor.rs index 3a1627a57..360fcafc7 100644 --- a/src/sdam/monitor.rs +++ b/src/sdam/monitor.rs @@ -6,7 +6,7 @@ use std::{ time::{Duration, Instant}, }; -use bson::doc; +use crate::bson::doc; use tokio::sync::watch; use super::{ diff --git a/src/sdam/server.rs b/src/sdam/server.rs index ba6315a2c..a956716b7 100644 --- a/src/sdam/server.rs +++ b/src/sdam/server.rs @@ -37,7 +37,7 @@ impl Server { options: ClientOptions, connection_establisher: ConnectionEstablisher, topology_updater: TopologyUpdater, - topology_id: bson::oid::ObjectId, + topology_id: crate::bson::oid::ObjectId, ) -> Arc { Arc::new(Self { pool: ConnectionPool::new( diff --git a/src/sdam/test.rs b/src/sdam/test.rs index 3d8e92427..a8699d547 100644 --- a/src/sdam/test.rs +++ b/src/sdam/test.rs @@ -3,7 +3,7 @@ use std::{ time::{Duration, Instant}, }; -use bson::doc; +use crate::bson::doc; use crate::{ client::options::{ClientOptions, ServerAddress}, @@ -346,7 +346,7 @@ fn ipv6_invalid_me() { me: Some("[::1]:8191".to_string()), ..Default::default() }, - raw_command_response: bson::RawDocumentBuf::new(), + raw_command_response: crate::bson::RawDocumentBuf::new(), cluster_time: None, })), }; diff --git a/src/sdam/topology.rs b/src/sdam/topology.rs index 66ff07129..7270d1daa 100644 --- a/src/sdam/topology.rs +++ b/src/sdam/topology.rs @@ -5,7 +5,7 @@ use std::{ time::Duration, }; -use bson::oid::ObjectId; +use crate::bson::oid::ObjectId; use futures_util::{ stream::{FuturesUnordered, StreamExt}, FutureExt, diff --git a/src/search_index.rs b/src/search_index.rs index b701f33e9..d16b3f9b0 100644 --- a/src/search_index.rs +++ b/src/search_index.rs @@ -1,6 +1,6 @@ use crate::bson::Document; -use bson::doc; +use crate::bson::doc; use serde::{Deserialize, Serialize}; use typed_builder::TypedBuilder; diff --git a/src/selection_criteria.rs b/src/selection_criteria.rs index 174c6b223..805f54d78 100644 --- a/src/selection_criteria.rs +++ b/src/selection_criteria.rs @@ -370,7 +370,7 @@ mod test { ); let read_pref = ReadPreference::Secondary { options }; - let doc = bson::to_document(&read_pref).unwrap(); + let doc = crate::bson::to_document(&read_pref).unwrap(); assert_eq!( doc, diff --git a/src/serde_util.rs b/src/serde_util.rs index 77004212a..35d8896c6 100644 --- a/src/serde_util.rs +++ b/src/serde_util.rs @@ -73,7 +73,7 @@ pub(crate) fn serialize_u32_option_as_i32( serializer: S, ) -> std::result::Result { match val { - Some(ref val) => bson::serde_helpers::serialize_u32_as_i32(val, serializer), + Some(ref val) => crate::bson::serde_helpers::serialize_u32_as_i32(val, serializer), None => serializer.serialize_none(), } } @@ -101,7 +101,7 @@ pub(crate) fn serialize_u64_option_as_i64( serializer: S, ) -> std::result::Result { match val { - Some(ref v) => bson::serde_helpers::serialize_u64_as_i64(v, serializer), + Some(ref v) => crate::bson::serde_helpers::serialize_u64_as_i64(v, serializer), None => serializer.serialize_none(), } } @@ -137,7 +137,7 @@ pub(crate) fn serialize_result_error_as_string( #[cfg(feature = "aws-auth")] pub(crate) fn deserialize_datetime_option_from_double_or_string<'de, D>( deserializer: D, -) -> std::result::Result, D::Error> +) -> std::result::Result, D::Error> where D: Deserializer<'de>, { @@ -152,9 +152,9 @@ where #[allow(clippy::cast_possible_truncation)] AwsDateTime::Double(seconds) => { let millis = seconds * 1000.0; - bson::DateTime::from_millis(millis as i64) + crate::bson::DateTime::from_millis(millis as i64) } - AwsDateTime::String(string) => bson::DateTime::parse_rfc3339_str(string) + AwsDateTime::String(string) => crate::bson::DateTime::parse_rfc3339_str(string) .map_err(|e| serde::de::Error::custom(format!("invalid RFC 3339 string: {}", e)))?, }; diff --git a/src/sync/change_stream.rs b/src/sync/change_stream.rs index f7e2b5e76..d74e5bbc7 100644 --- a/src/sync/change_stream.rs +++ b/src/sync/change_stream.rs @@ -181,8 +181,7 @@ where /// The session provided must be the same session used to create the change stream. /// /// ``` - /// # use bson::{doc, Document}; - /// # use mongodb::sync::Client; + /// # use mongodb::{bson::{self, doc, Document}, sync::Client}; /// # fn main() { /// # async { /// # let client = Client::with_uri_str("foo")?; diff --git a/src/sync/cursor.rs b/src/sync/cursor.rs index 5c1d7724a..69baaef2c 100644 --- a/src/sync/cursor.rs +++ b/src/sync/cursor.rs @@ -320,8 +320,7 @@ where /// functionality of `Iterator` is not needed. /// /// ``` - /// # use bson::{doc, Document}; - /// # use mongodb::sync::Client; + /// # use mongodb::{bson::{doc, Document}, sync::Client}; /// # fn foo() -> mongodb::error::Result<()> { /// # let client = Client::with_uri_str("foo")?; /// # let coll = client.database("foo").collection::("bar"); diff --git a/src/test/auth.rs b/src/test/auth.rs index 30843563f..93ba7ef1c 100644 --- a/src/test/auth.rs +++ b/src/test/auth.rs @@ -36,7 +36,7 @@ async fn plain_auth() { authenticated: String, } - let doc: TestDocument = bson::from_document(doc).unwrap(); + let doc: TestDocument = crate::bson::from_document(doc).unwrap(); assert_eq!( doc, diff --git a/src/test/auth/aws.rs b/src/test/auth/aws.rs index 996181832..4319dfe70 100644 --- a/src/test/auth/aws.rs +++ b/src/test/auth/aws.rs @@ -35,7 +35,7 @@ async fn credential_caching() { coll.find_one(doc! {}).await.unwrap(); assert!(cached_credential().await.is_some()); - let now = bson::DateTime::now(); + let now = crate::bson::DateTime::now(); set_cached_expiration(now).await; let client = get_client().await; diff --git a/src/test/change_stream.rs b/src/test/change_stream.rs index 7ec602084..5139a31fa 100644 --- a/src/test/change_stream.rs +++ b/src/test/change_stream.rs @@ -1,4 +1,4 @@ -use bson::{doc, Bson, Document}; +use crate::bson::{doc, Bson, Document}; use futures_util::{StreamExt, TryStreamExt}; use crate::{ @@ -681,8 +681,8 @@ async fn transaction_fields() -> Result<()> { // run because it's just asserting that this compiles. #[allow(unreachable_code, unused_variables, clippy::diverging_sub_expression)] async fn _collection_watch_typed() { - let coll: Collection = unimplemented!(); + let coll: Collection = unimplemented!(); let mut stream = coll.watch().await.unwrap(); - let _: Option>> = + let _: Option>> = stream.next().await; } diff --git a/src/test/client.rs b/src/test/client.rs index eecad2ecd..f3ff306ca 100644 --- a/src/test/client.rs +++ b/src/test/client.rs @@ -1,6 +1,6 @@ use std::{borrow::Cow, collections::HashMap, future::IntoFuture, net::Ipv6Addr, time::Duration}; -use bson::Document; +use crate::bson::Document; use serde::{Deserialize, Serialize}; use crate::{ @@ -74,7 +74,7 @@ async fn metadata_sent_in_handshake() { .get_document("clientMetadata") .unwrap() .clone(); - let metadata: ClientMetadata = bson::from_document(metadata_document).unwrap(); + let metadata: ClientMetadata = crate::bson::from_document(metadata_document).unwrap(); assert_eq!(metadata.driver.name, "mongo-rust-driver"); assert_eq!(metadata.driver.version, env!("CARGO_PKG_VERSION")); diff --git a/src/test/coll.rs b/src/test/coll.rs index a0816f97d..86982a49e 100644 --- a/src/test/coll.rs +++ b/src/test/coll.rs @@ -578,7 +578,7 @@ async fn delete_hint_test(options: Option, name: &str) { .unwrap() .get("hint") .cloned() - .map(|bson| bson::from_bson(bson).unwrap()); + .map(|bson| crate::bson::from_bson(bson).unwrap()); let expected_hint = options.and_then(|options| options.hint); assert_eq!(event_hint, expected_hint); } @@ -626,7 +626,7 @@ async fn find_one_and_delete_hint_test(options: Option, .command .get("hint") .cloned() - .map(|bson| bson::from_bson(bson).unwrap()); + .map(|bson| crate::bson::from_bson(bson).unwrap()); let expected_hint = options.and_then(|options| options.hint); assert_eq!(event_hint, expected_hint); } diff --git a/src/test/csfle.rs b/src/test/csfle.rs index 30026b506..b34945bf6 100644 --- a/src/test/csfle.rs +++ b/src/test/csfle.rs @@ -20,8 +20,8 @@ mod spec; // requires environment variables listed below use std::{env, path::PathBuf}; +use crate::bson::{doc, Document, RawBson}; use anyhow::Context; -use bson::{doc, Document, RawBson}; use mongocrypt::ctx::{Algorithm, KmsProvider, KmsProviderType}; use once_cell::sync::Lazy; @@ -127,8 +127,8 @@ pub(crate) static LOCAL_KMS: Lazy = Lazy::new(|| { ( KmsProvider::local(), doc! { - "key": bson::Binary { - subtype: bson::spec::BinarySubtype::Generic, + "key": crate::bson::Binary { + subtype: crate::bson::spec::BinarySubtype::Generic, bytes: base64::decode(&*CSFLE_LOCAL_KEY).unwrap(), }, }, @@ -262,7 +262,7 @@ async fn custom_endpoint_setup(valid: bool) -> Result { async fn validate_roundtrip( client_encryption: &ClientEncryption, - key_id: bson::Binary, + key_id: crate::bson::Binary, ) -> Result<()> { let value = RawBson::String("test".to_string()); let encrypted = client_encryption diff --git a/src/test/csfle/kmip.rs b/src/test/csfle/kmip.rs index e7dc20b2b..a4231c54f 100644 --- a/src/test/csfle/kmip.rs +++ b/src/test/csfle/kmip.rs @@ -460,7 +460,7 @@ mod corpus { } if allowed { let bin = match value { - bson::Bson::Binary(b) => b, + crate::bson::Bson::Binary(b) => b, _ => { return Err(failure!( "expected value {:?} should be Binary, got {:?}", @@ -470,7 +470,7 @@ mod corpus { } }; let actual_bin = match actual_value { - bson::Bson::Binary(b) => b, + crate::bson::Bson::Binary(b) => b, _ => { return Err(failure!( "actual value {:?} should be Binary, got {:?}", @@ -503,9 +503,9 @@ mod corpus { } new_obj.insert(name.clone(), value.clone()); } - let bson: bson::Bson = serde_json::Value::Object(new_obj).try_into()?; + let bson: crate::bson::Bson = serde_json::Value::Object(new_obj).try_into()?; match bson { - bson::Bson::Document(d) => Ok(d), + crate::bson::Bson::Document(d) => Ok(d), _ => Err(failure!("expected document, got {:?}", bson)), } } diff --git a/src/test/csfle/prose.rs b/src/test/csfle/prose.rs index 6e0280b3d..2766c2f12 100644 --- a/src/test/csfle/prose.rs +++ b/src/test/csfle/prose.rs @@ -97,7 +97,7 @@ async fn custom_key_material() -> Result<()> { .await? .unwrap(); datakeys.delete_one(doc! { "_id": id}).await?; - let new_key_id = bson::Binary::from_uuid(bson::Uuid::from_bytes([0; 16])); + let new_key_id = crate::bson::Binary::from_uuid(crate::bson::Uuid::from_bytes([0; 16])); key_doc.insert("_id", new_key_id.clone()); datakeys.insert_one(key_doc).await?; diff --git a/src/test/cursor.rs b/src/test/cursor.rs index 5b233766b..c1061938b 100644 --- a/src/test/cursor.rs +++ b/src/test/cursor.rs @@ -238,12 +238,13 @@ async fn session_cursor_with_type() { .await .unwrap(); - let mut cursor: crate::SessionCursor = + let mut cursor: crate::SessionCursor = coll.find(doc! {}).session(&mut session).await.unwrap(); let _ = cursor.next(&mut session).await.unwrap().unwrap(); - let mut cursor_with_type: crate::SessionCursor = cursor.with_type(); + let mut cursor_with_type: crate::SessionCursor = + cursor.with_type(); let _ = cursor_with_type.next(&mut session).await.unwrap().unwrap(); } diff --git a/src/test/db.rs b/src/test/db.rs index b1d26ddab..a77821393 100644 --- a/src/test/db.rs +++ b/src/test/db.rs @@ -1,6 +1,6 @@ use std::cmp::Ord; -use bson::RawDocumentBuf; +use crate::bson::RawDocumentBuf; use futures::{stream::TryStreamExt, StreamExt}; use serde::Deserialize; @@ -187,7 +187,7 @@ async fn collection_management() { assert_eq!(colls[0].name, format!("{}1", function_name!())); assert_eq!(colls[0].collection_type, CollectionType::Collection); assert_eq!( - bson::to_document(&colls[0].options).expect("serialization should succeed"), + crate::bson::to_document(&colls[0].options).expect("serialization should succeed"), doc! {} ); assert!(!colls[0].info.read_only); @@ -331,7 +331,7 @@ async fn index_option_defaults_test(defaults: Option, name: #[test] fn deserialize_clustered_index_option_from_bool() { let options_doc = doc! { "clusteredIndex": true }; - let options: CreateCollectionOptions = bson::from_document(options_doc).unwrap(); + let options: CreateCollectionOptions = crate::bson::from_document(options_doc).unwrap(); let clustered_index = options .clustered_index .expect("deserialized options should include clustered_index"); diff --git a/src/test/documentation_examples.rs b/src/test/documentation_examples.rs index 7f270171a..ab065a3a9 100644 --- a/src/test/documentation_examples.rs +++ b/src/test/documentation_examples.rs @@ -1,6 +1,6 @@ mod aggregation_data; -use bson::Document; +use crate::bson::Document; use futures::TryStreamExt; use crate::{ @@ -1316,9 +1316,11 @@ async fn stable_api_examples() -> GenericResult<()> { // Start Versioned API Example 5 // With the `bson-chrono-0_4` feature enabled, this function can be dropped in favor of using // `chrono::DateTime` values directly. - fn iso_date(text: &str) -> Result> { + fn iso_date(text: &str) -> Result> { let chrono_dt = chrono::DateTime::parse_from_rfc3339(text)?; - Ok(bson::DateTime::from_millis(chrono_dt.timestamp_millis())) + Ok(crate::bson::DateTime::from_millis( + chrono_dt.timestamp_millis(), + )) } db.collection("sales").insert_many(vec![ doc! { "_id" : 1, "item" : "abc", "price" : 10, "quantity" : 2, "date" : iso_date("2021-01-01T08:00:00Z")? }, diff --git a/src/test/documentation_examples/aggregation_data.rs b/src/test/documentation_examples/aggregation_data.rs index b4fd5d449..4added6f1 100644 --- a/src/test/documentation_examples/aggregation_data.rs +++ b/src/test/documentation_examples/aggregation_data.rs @@ -1,4 +1,4 @@ -use bson::{doc, DateTime}; +use crate::bson::{doc, DateTime}; use crate::Database; diff --git a/src/test/spec.rs b/src/test/spec.rs index d333f4f82..c0557d76d 100644 --- a/src/test/spec.rs +++ b/src/test/spec.rs @@ -105,7 +105,7 @@ fn deserialize_spec_tests_common( ) }); - let deserializer = bson::Deserializer::new(test_bson); + let deserializer = crate::bson::Deserializer::new(test_bson); let test: T = serde_path_to_error::deserialize(deserializer).unwrap_or_else(|e| { panic!( "Failed to deserialize test BSON to {} in {:?}: {}", diff --git a/src/test/spec/faas.rs b/src/test/spec/faas.rs index 64fff75be..2562a1ee1 100644 --- a/src/test/spec/faas.rs +++ b/src/test/spec/faas.rs @@ -1,6 +1,6 @@ use std::env; -use bson::rawdoc; +use crate::bson::rawdoc; use crate::{ cmap::establish::handshake::{ diff --git a/src/test/spec/handshake.rs b/src/test/spec/handshake.rs index 28c44011f..11a071371 100644 --- a/src/test/spec/handshake.rs +++ b/src/test/spec/handshake.rs @@ -1,6 +1,6 @@ use std::time::Instant; -use bson::oid::ObjectId; +use crate::bson::oid::ObjectId; use crate::{ cmap::{ diff --git a/src/test/spec/oidc.rs b/src/test/spec/oidc.rs index edf591755..a6914f52f 100644 --- a/src/test/spec/oidc.rs +++ b/src/test/spec/oidc.rs @@ -74,6 +74,7 @@ fn remove_mechanism_properties_placeholder(test_file: &mut TestFile) { mod basic { use crate::{ + bson::{doc, Document}, client::auth::{oidc, AuthMechanism, Credential}, options::ClientOptions, test::{ @@ -82,7 +83,6 @@ mod basic { }, Client, }; - use bson::{doc, Document}; use futures_util::FutureExt; use std::{ sync::Arc, @@ -749,7 +749,7 @@ mod basic { let mut opts = ClientOptions::parse(&*MONGODB_URI_SINGLE).await?; opts.credential = Credential::builder() .mechanism(AuthMechanism::MongoDbOidc) - .mechanism_properties(bson::doc! { + .mechanism_properties(crate::bson::doc! { ALLOWED_HOSTS_PROP_STR: [], }) .oidc_callback(oidc::Callback::human(move |_| { @@ -790,7 +790,7 @@ mod basic { let mut opts = ClientOptions::parse(&*MONGODB_URI_SINGLE).await?; opts.credential = Credential::builder() .mechanism(AuthMechanism::MongoDbOidc) - .mechanism_properties(bson::doc! { + .mechanism_properties(crate::bson::doc! { ALLOWED_HOSTS_PROP_STR: ["example.com"], }) .oidc_callback(oidc::Callback::human(move |_| { diff --git a/src/test/spec/read_write_concern/connection_string.rs b/src/test/spec/read_write_concern/connection_string.rs index b1b82ee4a..8fd8ebe1b 100644 --- a/src/test/spec/read_write_concern/connection_string.rs +++ b/src/test/spec/read_write_concern/connection_string.rs @@ -54,7 +54,7 @@ async fn run_connection_string_test(test_file: TestFile) { &normalize_write_concern_doc( options .write_concern - .map(|w| bson::to_document(&w).expect(&test_case.description)) + .map(|w| crate::bson::to_document(&w).expect(&test_case.description)) .unwrap_or_default() ), write_concern, diff --git a/src/test/spec/read_write_concern/document.rs b/src/test/spec/read_write_concern/document.rs index 0eeca5c2b..8ad1fdda5 100644 --- a/src/test/spec/read_write_concern/document.rs +++ b/src/test/spec/read_write_concern/document.rs @@ -31,7 +31,7 @@ async fn run_document_test(test_file: TestFile) { if let Some(specified_write_concern_document) = test_case.write_concern { let specified_write_concern = - match bson::from_document::(specified_write_concern_document) + match crate::bson::from_document::(specified_write_concern_document) .map_err(Error::from) .and_then(|wc| wc.validate().map(|_| wc)) { @@ -76,7 +76,7 @@ async fn run_document_test(test_file: TestFile) { ); } - let actual_write_concern_document = bson::to_document(&specified_write_concern) + let actual_write_concern_document = crate::bson::to_document(&specified_write_concern) .unwrap_or_else(|err| { panic!( "Write concern serialization should succeed but got {:?}: {}", @@ -101,14 +101,14 @@ async fn run_document_test(test_file: TestFile) { } let specified_read_concern: ReadConcern = - bson::from_document(specified_read_concern_document).unwrap_or_else(|err| { + crate::bson::from_document(specified_read_concern_document).unwrap_or_else(|err| { panic!( "Read concern deserialization should succeed but got {:?}: {}", err, description, ) }); - let actual_read_concern_document = bson::to_document(&specified_read_concern) + let actual_read_concern_document = crate::bson::to_document(&specified_read_concern) .unwrap_or_else(|err| { panic!( "Read concern serialization should succeed but got: {:?}: {}", diff --git a/src/test/spec/retryable_reads.rs b/src/test/spec/retryable_reads.rs index a86d89118..9ad4f1517 100644 --- a/src/test/spec/retryable_reads.rs +++ b/src/test/spec/retryable_reads.rs @@ -1,6 +1,6 @@ use std::{future::IntoFuture, time::Duration}; -use bson::doc; +use crate::bson::doc; use crate::{ error::Result, @@ -193,7 +193,7 @@ async fn retry_read_different_mongos() { .await; let result = client .database("test") - .collection::("retry_read_different_mongos") + .collection::("retry_read_different_mongos") .find(doc! {}) .await; assert!(result.is_err()); @@ -247,7 +247,7 @@ async fn retry_read_same_mongos() { .await; let result = client .database("test") - .collection::("retry_read_same_mongos") + .collection::("retry_read_same_mongos") .find(doc! {}) .await; assert!(result.is_ok(), "{:?}", result); diff --git a/src/test/spec/retryable_writes.rs b/src/test/spec/retryable_writes.rs index 9c12b367f..6b95df442 100644 --- a/src/test/spec/retryable_writes.rs +++ b/src/test/spec/retryable_writes.rs @@ -1,6 +1,6 @@ use std::{sync::Arc, time::Duration}; -use bson::Bson; +use crate::bson::Bson; use tokio::sync::Mutex; use crate::{ @@ -338,7 +338,7 @@ async fn retry_write_different_mongos() { .await; let result = client .database("test") - .collection::("retry_write_different_mongos") + .collection::("retry_write_different_mongos") .insert_one(doc! {}) .await; assert!(result.is_err()); @@ -393,7 +393,7 @@ async fn retry_write_same_mongos() { .await; let result = client .database("test") - .collection::("retry_write_same_mongos") + .collection::("retry_write_same_mongos") .insert_one(doc! {}) .await; assert!(result.is_ok(), "{:?}", result); diff --git a/src/test/spec/sdam.rs b/src/test/spec/sdam.rs index b4240ac91..49a1ee19e 100644 --- a/src/test/spec/sdam.rs +++ b/src/test/spec/sdam.rs @@ -1,6 +1,6 @@ use std::time::Duration; -use bson::{doc, Document}; +use crate::bson::{doc, Document}; use crate::{ event::sdam::SdamEvent, diff --git a/src/test/spec/trace.rs b/src/test/spec/trace.rs index 9f2820922..0d7b38c3a 100644 --- a/src/test/spec/trace.rs +++ b/src/test/spec/trace.rs @@ -465,7 +465,7 @@ fn topology_description_tracing_representation() { ServerDescription::new(&ServerAddress::default()), ); - let oid = bson::oid::ObjectId::new(); + let oid = crate::bson::oid::ObjectId::new(); let description = TopologyDescription { single_seed: false, set_name: Some("myReplicaSet".to_string()), diff --git a/src/test/spec/unified_runner/entity.rs b/src/test/spec/unified_runner/entity.rs index 9daf9810e..cdaacb677 100644 --- a/src/test/spec/unified_runner/entity.rs +++ b/src/test/spec/unified_runner/entity.rs @@ -6,7 +6,7 @@ use std::{ time::Duration, }; -use bson::to_document; +use crate::bson::to_document; use time::OffsetDateTime; use tokio::sync::{mpsc, oneshot, Mutex, RwLock}; @@ -70,7 +70,7 @@ impl std::fmt::Debug for crate::client_encryption::ClientEncryption { pub(crate) struct ClientEntity { /// This is None if a `close` operation has been executed for this entity. pub(crate) client: Option, - pub(crate) topology_id: bson::oid::ObjectId, + pub(crate) topology_id: crate::bson::oid::ObjectId, events: EventBuffer, observe_events: Option>, ignore_command_names: Option>, @@ -505,7 +505,7 @@ impl Entity { } /// If this entity is descended from a client entity, returns the topology ID for that client. - pub(crate) async fn client_topology_id(&self) -> Option { + pub(crate) async fn client_topology_id(&self) -> Option { match self { Entity::Client(client_entity) => Some(client_entity.topology_id), Entity::Database(database) => Some(database.client().topology().id), diff --git a/src/test/spec/unified_runner/matcher.rs b/src/test/spec/unified_runner/matcher.rs index 6d75ba376..72fe943cd 100644 --- a/src/test/spec/unified_runner/matcher.rs +++ b/src/test/spec/unified_runner/matcher.rs @@ -193,7 +193,7 @@ pub(crate) fn tracing_events_match( }; } - let serialized_fields = bson::to_document(&actual.fields) + let serialized_fields = crate::bson::to_document(&actual.fields) .map_err(|e| format!("Failed to serialize tracing fields to document: {}", e))?; results_match( diff --git a/src/test/spec/unified_runner/operation.rs b/src/test/spec/unified_runner/operation.rs index 82e2bcd45..eee1016c7 100644 --- a/src/test/spec/unified_runner/operation.rs +++ b/src/test/spec/unified_runner/operation.rs @@ -317,8 +317,8 @@ pub(crate) enum Expectation { fn deserialize_op<'de, 'a, T: 'a + DeserializeOwned + TestOperation>( value: Document, -) -> std::result::Result, bson::de::Error> { - bson::from_document::(value).map(|op| Box::new(op) as Box) +) -> std::result::Result, crate::bson::de::Error> { + crate::bson::from_document::(value).map(|op| Box::new(op) as Box) } impl<'de> Deserialize<'de> for Operation { diff --git a/src/test/spec/unified_runner/operation/collection.rs b/src/test/spec/unified_runner/operation/collection.rs index 7d663938e..ec4893191 100644 --- a/src/test/spec/unified_runner/operation/collection.rs +++ b/src/test/spec/unified_runner/operation/collection.rs @@ -1,4 +1,5 @@ use crate::{ + bson::{doc, Bson, Document}, error::Result, options::{AggregateOptions, CreateCollectionOptions, DropCollectionOptions}, test::spec::unified_runner::{ @@ -9,7 +10,6 @@ use crate::{ Collection, Database, }; -use bson::{doc, Bson, Document}; use futures::{future::BoxFuture, TryStreamExt}; use futures_util::FutureExt; use serde::Deserialize; diff --git a/src/test/spec/unified_runner/operation/command.rs b/src/test/spec/unified_runner/operation/command.rs index 5bf7d0fda..ba7a08960 100644 --- a/src/test/spec/unified_runner/operation/command.rs +++ b/src/test/spec/unified_runner/operation/command.rs @@ -1,5 +1,6 @@ use crate::{ action::Action, + bson::{to_bson, Document}, error::Result, options::{RunCursorCommandOptions, SelectionCriteria}, test::spec::unified_runner::{ @@ -9,7 +10,6 @@ use crate::{ TestRunner, }, }; -use bson::{to_bson, Document}; use futures::{future::BoxFuture, TryStreamExt}; use futures_util::FutureExt; use serde::Deserialize; @@ -93,7 +93,7 @@ impl TestOperation for RunCursorCommand { } }; - Ok(Some(bson::to_bson(&result)?.into())) + Ok(Some(crate::bson::to_bson(&result)?.into())) } .boxed() } diff --git a/src/test/spec/unified_runner/operation/count.rs b/src/test/spec/unified_runner/operation/count.rs index bfae42dde..c4d31aba5 100644 --- a/src/test/spec/unified_runner/operation/count.rs +++ b/src/test/spec/unified_runner/operation/count.rs @@ -1,4 +1,5 @@ use crate::{ + bson::{Bson, Document}, error::Result, options::{CountOptions, DistinctOptions, EstimatedDocumentCountOptions}, test::spec::unified_runner::{ @@ -8,7 +9,6 @@ use crate::{ TestRunner, }, }; -use bson::{Bson, Document}; use futures::future::BoxFuture; use futures_util::FutureExt; use serde::Deserialize; diff --git a/src/test/spec/unified_runner/operation/csfle.rs b/src/test/spec/unified_runner/operation/csfle.rs index f095949ae..766786767 100644 --- a/src/test/spec/unified_runner/operation/csfle.rs +++ b/src/test/spec/unified_runner/operation/csfle.rs @@ -41,7 +41,7 @@ impl TestOperation for GetKeyByAltName { #[derive(Debug, Deserialize)] #[serde(rename_all = "camelCase", deny_unknown_fields)] pub(super) struct DeleteKey { - id: bson::Binary, + id: crate::bson::Binary, } impl TestOperation for DeleteKey { @@ -53,9 +53,9 @@ impl TestOperation for DeleteKey { async move { let ce = test_runner.get_client_encryption(id).await; let result = ce.delete_key(&self.id).await?; - Ok(Some(Entity::Bson(Bson::Document(bson::to_document( - &result, - )?)))) + Ok(Some(Entity::Bson(Bson::Document( + crate::bson::to_document(&result)?, + )))) } .boxed() } @@ -64,7 +64,7 @@ impl TestOperation for DeleteKey { #[derive(Debug, Deserialize)] #[serde(rename_all = "camelCase", deny_unknown_fields)] pub(super) struct GetKey { - id: bson::Binary, + id: crate::bson::Binary, } impl TestOperation for GetKey { @@ -88,7 +88,7 @@ impl TestOperation for GetKey { #[derive(Debug, Deserialize)] #[serde(rename_all = "camelCase", deny_unknown_fields)] pub(super) struct AddKeyAltName { - id: bson::Binary, + id: crate::bson::Binary, key_alt_name: String, } @@ -127,7 +127,7 @@ impl<'de> Deserialize<'de> for CreateDataKey { struct TestOptions { master_key: Option, key_alt_names: Option>, - key_material: Option, + key_material: Option, } #[derive(Deserialize)] #[serde(rename_all = "camelCase", deny_unknown_fields)] @@ -197,7 +197,7 @@ impl TestOperation for GetKeys { #[derive(Debug, Deserialize)] #[serde(rename_all = "camelCase", deny_unknown_fields)] pub(super) struct RemoveKeyAltName { - id: bson::Binary, + id: crate::bson::Binary, key_alt_name: String, } diff --git a/src/test/spec/unified_runner/operation/delete.rs b/src/test/spec/unified_runner/operation/delete.rs index 73b8cab40..fa2ec2f44 100644 --- a/src/test/spec/unified_runner/operation/delete.rs +++ b/src/test/spec/unified_runner/operation/delete.rs @@ -1,4 +1,5 @@ use crate::{ + bson::{to_bson, Document}, error::Result, options::DeleteOptions, test::spec::unified_runner::{ @@ -7,7 +8,6 @@ use crate::{ TestRunner, }, }; -use bson::{to_bson, Document}; use futures::future::BoxFuture; use futures_util::FutureExt; use serde::Deserialize; diff --git a/src/test/spec/unified_runner/operation/find.rs b/src/test/spec/unified_runner/operation/find.rs index 55e127d30..a2279fd72 100644 --- a/src/test/spec/unified_runner/operation/find.rs +++ b/src/test/spec/unified_runner/operation/find.rs @@ -1,6 +1,7 @@ use std::time::Duration; use crate::{ + bson::{to_bson, Bson, Document}, error::Result, options::{ Collation, @@ -21,7 +22,6 @@ use crate::{ TestRunner, }, }; -use bson::{to_bson, Bson, Document}; use futures::{future::BoxFuture, TryStreamExt}; use futures_util::FutureExt; use serde::{Deserialize, Deserializer}; diff --git a/src/test/spec/unified_runner/operation/gridfs.rs b/src/test/spec/unified_runner/operation/gridfs.rs index 78f3f4174..684b71470 100644 --- a/src/test/spec/unified_runner/operation/gridfs.rs +++ b/src/test/spec/unified_runner/operation/gridfs.rs @@ -1,9 +1,9 @@ use crate::{ + bson::{Bson, Document}, error::Result, gridfs::{GridFsDownloadByNameOptions, GridFsUploadOptions}, test::spec::unified_runner::{operation::TestOperation, Entity, TestRunner}, }; -use bson::{Bson, Document}; use futures::{future::BoxFuture, AsyncReadExt, AsyncWriteExt}; use futures_util::FutureExt; use serde::Deserialize; diff --git a/src/test/spec/unified_runner/operation/index.rs b/src/test/spec/unified_runner/operation/index.rs index eadcde403..2c96c0ff1 100644 --- a/src/test/spec/unified_runner/operation/index.rs +++ b/src/test/spec/unified_runner/operation/index.rs @@ -1,4 +1,5 @@ use crate::{ + bson::{Bson, Document}, error::Result, options::{DropIndexOptions, IndexOptions, ListIndexesOptions}, test::spec::unified_runner::{ @@ -8,7 +9,6 @@ use crate::{ }, IndexModel, }; -use bson::{Bson, Document}; use futures::{future::BoxFuture, TryStreamExt}; use futures_util::FutureExt; use serde::Deserialize; @@ -78,7 +78,7 @@ impl TestOperation for ListIndexes { }; let indexes: Vec = indexes .iter() - .map(|index| bson::to_document(index).unwrap()) + .map(|index| crate::bson::to_document(index).unwrap()) .collect(); Ok(Some(Bson::from(indexes).into())) } diff --git a/src/test/spec/unified_runner/operation/insert.rs b/src/test/spec/unified_runner/operation/insert.rs index 8ec0517cd..016324445 100644 --- a/src/test/spec/unified_runner/operation/insert.rs +++ b/src/test/spec/unified_runner/operation/insert.rs @@ -1,6 +1,6 @@ use std::collections::HashMap; -use bson::{doc, to_bson, Bson, Document}; +use crate::bson::{doc, to_bson, Bson, Document}; use serde::Deserialize; use crate::{ diff --git a/src/test/spec/unified_runner/operation/iteration.rs b/src/test/spec/unified_runner/operation/iteration.rs index 8667a733d..53fde5c13 100644 --- a/src/test/spec/unified_runner/operation/iteration.rs +++ b/src/test/spec/unified_runner/operation/iteration.rs @@ -1,8 +1,8 @@ use crate::{ + bson::Bson, error::Result, test::spec::unified_runner::{operation::TestOperation, Entity, TestCursor, TestRunner}, }; -use bson::Bson; use futures::{future::BoxFuture, StreamExt}; use futures_util::FutureExt; use serde::Deserialize; @@ -84,7 +84,7 @@ impl TestOperation for IterateUntilDocumentOrError { TestCursor::ChangeStream(stream) => { let mut stream = stream.lock().await; stream.next().await.map(|res| { - res.map(|ev| match bson::to_bson(&ev) { + res.map(|ev| match crate::bson::to_bson(&ev) { Ok(Bson::Document(doc)) => doc, _ => panic!("invalid serialization result"), }) diff --git a/src/test/spec/unified_runner/operation/list.rs b/src/test/spec/unified_runner/operation/list.rs index b443915dd..3dd8f9eba 100644 --- a/src/test/spec/unified_runner/operation/list.rs +++ b/src/test/spec/unified_runner/operation/list.rs @@ -1,5 +1,6 @@ use crate::{ action::Action, + bson::{Bson, Document}, error::Result, options::ListCollectionsOptions, test::spec::unified_runner::{ @@ -8,7 +9,6 @@ use crate::{ TestRunner, }, }; -use bson::{Bson, Document}; use futures::{future::BoxFuture, TryStreamExt}; use futures_util::FutureExt; use serde::Deserialize; @@ -35,7 +35,7 @@ impl TestOperation for ListDatabases { client.list_databases().with_options(self.options.clone()), ) .await?; - Ok(Some(bson::to_bson(&result)?.into())) + Ok(Some(crate::bson::to_bson(&result)?.into())) } .boxed() } @@ -103,7 +103,7 @@ impl TestOperation for ListCollections { cursor.try_collect::>().await? } }; - Ok(Some(bson::to_bson(&result)?.into())) + Ok(Some(crate::bson::to_bson(&result)?.into())) } .boxed() } diff --git a/src/test/spec/unified_runner/operation/rename.rs b/src/test/spec/unified_runner/operation/rename.rs index 750ea8985..0d4ca9a84 100644 --- a/src/test/spec/unified_runner/operation/rename.rs +++ b/src/test/spec/unified_runner/operation/rename.rs @@ -1,4 +1,4 @@ -use bson::{doc, Bson, Document}; +use crate::bson::{doc, Bson, Document}; use futures::FutureExt; use serde::Deserialize; @@ -25,11 +25,12 @@ impl TestOperation for Rename { async move { match test_runner.entities.read().await.get(id).unwrap() { Entity::Collection(c) => { - let args: RenameCollection = bson::from_document(self.0.clone()).unwrap(); + let args: RenameCollection = + crate::bson::from_document(self.0.clone()).unwrap(); args.run(c.clone(), test_runner).await } Entity::Bucket(b) => { - let args: RenameBucket = bson::from_document(self.0.clone()).unwrap(); + let args: RenameBucket = crate::bson::from_document(self.0.clone()).unwrap(); args.run(b.clone()).await } other => panic!("cannot execute rename on {:?}", other), diff --git a/src/test/spec/unified_runner/operation/search_index.rs b/src/test/spec/unified_runner/operation/search_index.rs index e09825865..3e33a80a2 100644 --- a/src/test/spec/unified_runner/operation/search_index.rs +++ b/src/test/spec/unified_runner/operation/search_index.rs @@ -1,4 +1,4 @@ -use bson::{to_bson, Bson, Document}; +use crate::bson::{to_bson, Bson, Document}; use futures_core::future::BoxFuture; use futures_util::{FutureExt, TryStreamExt}; use serde::Deserialize; diff --git a/src/test/spec/unified_runner/operation/update.rs b/src/test/spec/unified_runner/operation/update.rs index 374164ded..7a66c7294 100644 --- a/src/test/spec/unified_runner/operation/update.rs +++ b/src/test/spec/unified_runner/operation/update.rs @@ -1,4 +1,5 @@ use crate::{ + bson::{to_bson, Document}, error::Result, options::{ReplaceOptions, UpdateModifications, UpdateOptions}, test::spec::unified_runner::{ @@ -7,7 +8,6 @@ use crate::{ TestRunner, }, }; -use bson::{to_bson, Document}; use futures::future::BoxFuture; use futures_util::FutureExt; use serde::Deserialize; diff --git a/src/test/spec/unified_runner/test_file.rs b/src/test/spec/unified_runner/test_file.rs index c66032bfd..0754db530 100644 --- a/src/test/spec/unified_runner/test_file.rs +++ b/src/test/spec/unified_runner/test_file.rs @@ -564,7 +564,7 @@ impl ExpectError { }) => { let actual_result = partial_result .as_ref() - .map(|result| bson::to_bson(result).expect(&context)); + .map(|result| crate::bson::to_bson(result).expect(&context)); results_match(actual_result.as_ref(), expected_result, false, None) .expect(&context); } @@ -586,7 +586,7 @@ impl ExpectError { for (expected_index, expected_error) in write_errors { let actual_error = actual_write_errors.get(expected_index).expect(&context); - let actual_error = bson::to_bson(&actual_error) + let actual_error = crate::bson::to_bson(&actual_error) .map_err(|e| e.to_string()) .expect(&context); results_match(Some(&actual_error), expected_error, true, None).expect(&context); @@ -609,7 +609,7 @@ impl ExpectError { ); for (actual, expected) in actual_write_concern_errors.iter().zip(write_concern_errors) { - let actual = bson::to_bson(&actual) + let actual = crate::bson::to_bson(&actual) .map_err(|e| e.to_string()) .expect(&context); results_match(Some(&actual), expected, true, None).expect(&context); diff --git a/src/test/spec/v2_runner.rs b/src/test/spec/v2_runner.rs index ca940e5ce..d9115a7ea 100644 --- a/src/test/spec/v2_runner.rs +++ b/src/test/spec/v2_runner.rs @@ -275,7 +275,7 @@ impl TestContext { async fn run_operation( &mut self, operation: &Operation, - ) -> Option, crate::error::Error>> { + ) -> Option, crate::error::Error>> { if operation.name == "endSession" { let session = match &operation.object { Some(OperationObject::Session0) => &mut self.session0, @@ -361,7 +361,7 @@ impl OpRunner<'_> { &mut self, operation: &Operation, mut sessions: OpSessions<'_>, - ) -> Option, crate::error::Error>> { + ) -> Option, crate::error::Error>> { if operation.name == "withTransaction" { if !matches!(&operation.object, Some(OperationObject::Session0)) { panic!("invalid object for withTransaction: {:?}", operation.object); diff --git a/src/test/spec/v2_runner/csfle.rs b/src/test/spec/v2_runner/csfle.rs index 784e254fd..af752f7a4 100644 --- a/src/test/spec/v2_runner/csfle.rs +++ b/src/test/spec/v2_runner/csfle.rs @@ -1,4 +1,4 @@ -use bson::{doc, Document}; +use crate::bson::{doc, Document}; use mongocrypt::ctx::KmsProvider; use crate::{ diff --git a/src/test/spec/v2_runner/operation.rs b/src/test/spec/v2_runner/operation.rs index 40cf25c0f..7da7c1a57 100644 --- a/src/test/spec/v2_runner/operation.rs +++ b/src/test/spec/v2_runner/operation.rs @@ -311,7 +311,7 @@ impl<'de> Deserialize<'de> for Operation { fn deserialize_op<'de, 'a, Op: TestOperation + Deserialize<'de> + 'a>( arguments: Document, -) -> std::result::Result, bson::de::Error> { +) -> std::result::Result, crate::bson::de::Error> { Ok(Box::new(Op::deserialize(BsonDeserializer::new( Bson::Document(arguments), ))?)) @@ -344,7 +344,7 @@ impl TestOperation for DeleteMany { .with_options(self.options.clone()) .optional(session, |a, s| a.session(s)) .await?; - let result = bson::to_bson(&result)?; + let result = crate::bson::to_bson(&result)?; Ok(Some(result)) } .boxed() @@ -370,7 +370,7 @@ impl TestOperation for DeleteOne { .with_options(self.options.clone()) .optional(session, |a, s| a.session(s)) .await?; - let result = bson::to_bson(&result)?; + let result = crate::bson::to_bson(&result)?; Ok(Some(result)) } .boxed() @@ -440,7 +440,7 @@ impl TestOperation for InsertMany { .into_iter() .map(|(k, v)| (k.to_string(), v)) .collect(); - let ids = bson::to_bson(&ids)?; + let ids = crate::bson::to_bson(&ids)?; Ok(Some(Bson::from(doc! { "insertedIds": ids }))) } .boxed() @@ -468,7 +468,7 @@ impl TestOperation for InsertOne { .with_options(options) .optional(session, |a, s| a.session(s)) .await?; - let result = bson::to_bson(&result)?; + let result = crate::bson::to_bson(&result)?; Ok(Some(result)) } .boxed() @@ -495,7 +495,7 @@ impl TestOperation for UpdateMany { .with_options(self.options.clone()) .optional(session, |a, s| a.session(s)) .await?; - let result = bson::to_bson(&result)?; + let result = crate::bson::to_bson(&result)?; Ok(Some(result)) } .boxed() @@ -522,7 +522,7 @@ impl TestOperation for UpdateOne { .with_options(self.options.clone()) .optional(session, |a, s| a.session(s)) .await?; - let result = bson::to_bson(&result)?; + let result = crate::bson::to_bson(&result)?; Ok(Some(result)) } .boxed() @@ -729,7 +729,7 @@ impl TestOperation for ListCollections { cursor.try_collect::>().await? } }; - Ok(Some(bson::to_bson(&result)?)) + Ok(Some(crate::bson::to_bson(&result)?)) } .boxed() } @@ -781,7 +781,7 @@ impl TestOperation for ReplaceOne { .with_options(self.options.clone()) .optional(session, |a, s| a.session(s)) .await?; - let result = bson::to_bson(&result)?; + let result = crate::bson::to_bson(&result)?; Ok(Some(result)) } .boxed() @@ -808,7 +808,7 @@ impl TestOperation for FindOneAndUpdate { .with_options(self.options.clone()) .optional(session, |a, s| a.session(s)) .await?; - let result = bson::to_bson(&result)?; + let result = crate::bson::to_bson(&result)?; Ok(Some(result)) } .boxed() @@ -835,7 +835,7 @@ impl TestOperation for FindOneAndReplace { .with_options(self.options.clone()) .optional(session, |a, s| a.session(s)) .await?; - let result = bson::to_bson(&result)?; + let result = crate::bson::to_bson(&result)?; Ok(Some(result)) } .boxed() @@ -861,7 +861,7 @@ impl TestOperation for FindOneAndDelete { .with_options(self.options.clone()) .optional(session, |a, s| a.session(s)) .await?; - let result = bson::to_bson(&result)?; + let result = crate::bson::to_bson(&result)?; Ok(Some(result)) } .boxed() @@ -880,7 +880,7 @@ impl TestOperation for TargetedFailPoint { _client: &'a TestClient, ) -> BoxFuture<'a, Result>> { async move { - let command_document = bson::to_document(&self.fail_point).unwrap(); + let command_document = crate::bson::to_document(&self.fail_point).unwrap(); Ok(Some(command_document.into())) } .boxed() @@ -935,7 +935,7 @@ impl TestOperation for ListDatabases { .list_databases() .with_options(self.options.clone()) .await?; - Ok(Some(bson::to_bson(&result)?)) + Ok(Some(crate::bson::to_bson(&result)?)) } .boxed() } @@ -1267,7 +1267,7 @@ impl TestOperation for ListIndexes { }; let indexes: Vec = indexes .iter() - .map(|index| bson::to_document(index).unwrap()) + .map(|index| crate::bson::to_document(index).unwrap()) .collect(); Ok(Some(indexes.into())) } diff --git a/src/test/spec/v2_runner/test_event.rs b/src/test/spec/v2_runner/test_event.rs index f3f620da1..9b7b15c73 100644 --- a/src/test/spec/v2_runner/test_event.rs +++ b/src/test/spec/v2_runner/test_event.rs @@ -1,5 +1,8 @@ -use crate::{bson::Document, event, test::Matchable}; -use bson::Bson; +use crate::{ + bson::{Bson, Document}, + event, + test::Matchable, +}; use serde::Deserialize; #[derive(Debug, Deserialize)] diff --git a/src/test/spec/v2_runner/test_file.rs b/src/test/spec/v2_runner/test_file.rs index c8d98c63b..9b3d48b1a 100644 --- a/src/test/spec/v2_runner/test_file.rs +++ b/src/test/spec/v2_runner/test_file.rs @@ -1,6 +1,6 @@ use std::collections::HashMap; -use bson::{doc, from_document, Bson}; +use crate::bson::{doc, from_document, Bson}; use futures::TryStreamExt; use serde::{Deserialize, Deserializer}; @@ -134,7 +134,7 @@ impl<'de> Deserialize<'de> for ClientOptions { #[cfg(feature = "in-use-encryption")] let auto_encrypt_opts = uri_options .remove("autoEncryptOpts") - .map(bson::from_bson) + .map(crate::bson::from_bson) .transpose() .map_err(D::Error::custom)?; let uri = merge_uri_options(&DEFAULT_URI, Some(&uri_options), true); diff --git a/src/test/timeseries.rs b/src/test/timeseries.rs index 2405e1af0..81b5bab94 100644 --- a/src/test/timeseries.rs +++ b/src/test/timeseries.rs @@ -1,4 +1,4 @@ -use bson::doc; +use crate::bson::doc; use futures::TryStreamExt; use crate::{ diff --git a/src/test/util.rs b/src/test/util.rs index 4453ff0ed..cedd6b55f 100644 --- a/src/test/util.rs +++ b/src/test/util.rs @@ -156,7 +156,8 @@ impl TestClient { } if server_version_gte(4, 0).await && !mechanisms.is_empty() { - let ms: bson::Array = mechanisms.iter().map(|s| Bson::from(s.as_str())).collect(); + let ms: crate::bson::Array = + mechanisms.iter().map(|s| Bson::from(s.as_str())).collect(); cmd.insert("mechanisms", ms); } self.database(db.into().unwrap_or("admin")) @@ -239,7 +240,7 @@ impl TestClient { .database("admin") .run_command(hello.body.try_into()?) .await?; - Ok(bson::from_document(hello_response_doc)?) + Ok(crate::bson::from_document(hello_response_doc)?) } } diff --git a/src/test/util/fail_point.rs b/src/test/util/fail_point.rs index d1d88a056..a2bccb01e 100644 --- a/src/test/util/fail_point.rs +++ b/src/test/util/fail_point.rs @@ -16,7 +16,7 @@ impl Client { /// method should remain in scope while the fail point is intended for use. Upon drop, the /// guard will disable the fail point on the server. pub(crate) async fn enable_fail_point(&self, fail_point: FailPoint) -> Result { - let command = bson::to_document(&fail_point)?; + let command = crate::bson::to_document(&fail_point)?; self.database("admin") .run_command(command) .selection_criteria(fail_point.selection_criteria.clone()) diff --git a/src/test/util/matchable.rs b/src/test/util/matchable.rs index b42393e19..65070d140 100644 --- a/src/test/util/matchable.rs +++ b/src/test/util/matchable.rs @@ -1,6 +1,6 @@ use std::{any::Any, fmt::Debug, time::Duration}; -use bson::spec::ElementType; +use crate::bson::spec::ElementType; use crate::{ bson::{Bson, Document}, diff --git a/src/trace.rs b/src/trace.rs index 89a0743d7..4bdbf9317 100644 --- a/src/trace.rs +++ b/src/trace.rs @@ -21,7 +21,7 @@ pub(crate) trait TracingRepresentation { fn tracing_representation(&self) -> Self::Representation; } -impl TracingRepresentation for bson::oid::ObjectId { +impl TracingRepresentation for crate::bson::oid::ObjectId { type Representation = String; fn tracing_representation(&self) -> String { @@ -74,7 +74,7 @@ pub(crate) fn truncate_on_char_boundary(s: &mut String, new_len: usize) { } } -fn serialize_command_or_reply(doc: bson::Document, max_length_bytes: usize) -> String { +fn serialize_command_or_reply(doc: crate::bson::Document, max_length_bytes: usize) -> String { let mut ext_json = Bson::Document(doc).into_relaxed_extjson().to_string(); truncate_on_char_boundary(&mut ext_json, max_length_bytes); ext_json diff --git a/src/trace/command.rs b/src/trace/command.rs index 1ec22aafa..57d1f1d69 100644 --- a/src/trace/command.rs +++ b/src/trace/command.rs @@ -1,4 +1,4 @@ -use bson::oid::ObjectId; +use crate::bson::oid::ObjectId; use crate::{ event::command::CommandEvent, diff --git a/src/trace/connection.rs b/src/trace/connection.rs index 03cd1f13e..6b8d6f811 100644 --- a/src/trace/connection.rs +++ b/src/trace/connection.rs @@ -1,4 +1,4 @@ -use bson::oid::ObjectId; +use crate::bson::oid::ObjectId; use crate::{ event::cmap::{CmapEvent, ConnectionCheckoutFailedReason, ConnectionClosedReason}, diff --git a/src/trace/server_selection.rs b/src/trace/server_selection.rs index 742c25e82..16a2f0258 100644 --- a/src/trace/server_selection.rs +++ b/src/trace/server_selection.rs @@ -5,11 +5,11 @@ use super::{ SERVER_SELECTION_TRACING_EVENT_TARGET, }; use crate::{ + bson::oid::ObjectId, error::Error, sdam::{SelectedServer, TopologyDescription}, selection_criteria::SelectionCriteria, }; -use bson::oid::ObjectId; use std::time::{Duration, Instant}; impl TracingRepresentation for SelectionCriteria { diff --git a/src/trace/topology.rs b/src/trace/topology.rs index cd3b71161..19cebdb00 100644 --- a/src/trace/topology.rs +++ b/src/trace/topology.rs @@ -1,4 +1,4 @@ -use bson::oid::ObjectId; +use crate::bson::oid::ObjectId; use crate::{ event::sdam::{