bb8_mongodb/
lib.rs

1// Copyright (c) 2021 bb8-mongodb developers
2//
3// Licensed under the Apache License, Version 2.0
4// <LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0> or the MIT
5// license <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
6// option. All files in the project carrying such notice may not be copied,
7// modified, or distributed except according to those terms.
8
9//! A [`bb8`](https://docs.rs/bb8) connection manager for a [`MongoDB`](https://www.mongodb.com/) connection pool
10//!
11//! ** NOTE ** - The `bb8` version has been pinned to 0.8.1 for now due to bugs causing tokio timeouts.
12//!
13//! # Example
14//! ```
15//! # use anyhow::Result;
16//! # use bb8::Pool;
17//! # use bb8_mongodb::MongodbConnectionManager;
18//! # use mongodb::{bson::doc, options::{ClientOptions, Credential}};
19//! # use std::env;
20//! #
21//! # #[tokio::main]
22//! # async fn main() -> Result<()> {
23//! # let url = env::var("BB8_MONGODB_URL")?;
24//! # let user = env::var("BB8_MONGODB_USER").ok();
25//! # let password = env::var("BB8_MONGODB_PASSWORD").ok();
26//! // Setup the MongoDB `ClientOptions`
27//! let mut client_options = ClientOptions::parse(url).await?;
28//! client_options.credential = Some(
29//!     Credential::builder()
30//!         .username(user)
31//!         .password(password)
32//!         .build(),
33//! );
34//!
35//! // Setup the `bb8-mongodb` connection manager
36//! let connection_manager = MongodbConnectionManager::new(client_options, "admin");
37//! // Setup the `bb8` connection pool
38//! let pool = Pool::builder().build(connection_manager).await?;
39//! // Connect
40//! let conn = pool.get().await?;
41//! assert_eq!(conn.name(), "admin");
42//! // Run a command
43//! let doc = conn.run_command(doc! { "ping": 1 }).await?;
44//! // Check the result
45//! assert_eq!(doc! { "ok": 1 }, doc);
46//! # Ok(())
47//! # }
48//! ```
49//!
50
51// rustc lints
52#![cfg_attr(
53    all(feature = "unstable", nightly),
54    feature(
55        multiple_supertrait_upcastable,
56        must_not_suspend,
57        non_exhaustive_omitted_patterns_lint,
58        rustdoc_missing_doc_code_examples,
59        strict_provenance,
60    )
61)]
62#![cfg_attr(nightly, allow(single_use_lifetimes))]
63#![cfg_attr(
64    nightly,
65    deny(
66        absolute_paths_not_starting_with_crate,
67        ambiguous_glob_imports,
68        ambiguous_glob_reexports,
69        ambiguous_wide_pointer_comparisons,
70        anonymous_parameters,
71        array_into_iter,
72        asm_sub_register,
73        async_fn_in_trait,
74        bad_asm_style,
75        bare_trait_objects,
76        break_with_label_and_loop,
77        clashing_extern_declarations,
78        coherence_leak_check,
79        confusable_idents,
80        const_eval_mutable_ptr_in_final_value,
81        const_evaluatable_unchecked,
82        const_item_mutation,
83        dead_code,
84        deprecated,
85        deprecated_in_future,
86        deprecated_where_clause_location,
87        deref_into_dyn_supertrait,
88        deref_nullptr,
89        drop_bounds,
90        dropping_copy_types,
91        dropping_references,
92        duplicate_macro_attributes,
93        dyn_drop,
94        elided_lifetimes_in_associated_constant,
95        elided_lifetimes_in_paths,
96        ellipsis_inclusive_range_patterns,
97        explicit_outlives_requirements,
98        exported_private_dependencies,
99        ffi_unwind_calls,
100        forbidden_lint_groups,
101        forgetting_copy_types,
102        forgetting_references,
103        for_loops_over_fallibles,
104        function_item_references,
105        hidden_glob_reexports,
106        improper_ctypes,
107        improper_ctypes_definitions,
108        inline_no_sanitize,
109        internal_features,
110        invalid_from_utf8,
111        invalid_macro_export_arguments,
112        invalid_nan_comparisons,
113        invalid_value,
114        irrefutable_let_patterns,
115        keyword_idents_2018,
116        keyword_idents_2024,
117        large_assignments,
118        late_bound_lifetime_arguments,
119        legacy_derive_helpers,
120        let_underscore_drop,
121        macro_use_extern_crate,
122        map_unit_fn,
123        meta_variable_misuse,
124        missing_abi,
125        missing_copy_implementations,
126        missing_debug_implementations,
127        missing_docs,
128        mixed_script_confusables,
129        named_arguments_used_positionally,
130        never_type_fallback_flowing_into_unsafe,
131        no_mangle_generic_items,
132        non_ascii_idents,
133        non_camel_case_types,
134        non_contiguous_range_endpoints,
135        non_fmt_panics,
136        non_local_definitions,
137        non_shorthand_field_patterns,
138        non_snake_case,
139        non_upper_case_globals,
140        noop_method_call,
141        opaque_hidden_inferred_bound,
142        overlapping_range_endpoints,
143        path_statements,
144        private_bounds,
145        private_interfaces,
146        redundant_lifetimes,
147        redundant_semicolons,
148        refining_impl_trait_internal,
149        refining_impl_trait_reachable,
150        renamed_and_removed_lints,
151        repr_transparent_external_private_fields,
152        rust_2021_incompatible_closure_captures,
153        rust_2021_incompatible_or_patterns,
154        rust_2021_prefixes_incompatible_syntax,
155        rust_2021_prelude_collisions,
156        semicolon_in_expressions_from_macros,
157        special_module_name,
158        stable_features,
159        static_mut_refs,
160        suspicious_double_ref_op,
161        temporary_cstring_as_ptr,
162        trivial_bounds,
163        trivial_casts,
164        trivial_numeric_casts,
165        type_alias_bounds,
166        tyvar_behind_raw_pointer,
167        uncommon_codepoints,
168        unconditional_recursion,
169        uncovered_param_in_projection,
170        undefined_naked_function_abi,
171        unexpected_cfgs,
172        ungated_async_fn_track_caller,
173        uninhabited_static,
174        unit_bindings,
175        unknown_lints,
176        unknown_or_malformed_diagnostic_attributes,
177        unnameable_test_items,
178        unnameable_types,
179        unreachable_code,
180        unreachable_patterns,
181        unreachable_pub,
182        unsafe_code,
183        unsafe_op_in_unsafe_fn,
184        unstable_name_collisions,
185        unstable_syntax_pre_expansion,
186        unsupported_calling_conventions,
187        unused_allocation,
188        unused_assignments,
189        unused_associated_type_bounds,
190        unused_attributes,
191        unused_braces,
192        unused_comparisons,
193        unused_crate_dependencies,
194        unused_doc_comments,
195        unused_extern_crates,
196        unused_features,
197        unused_import_braces,
198        unused_imports,
199        unused_labels,
200        unused_lifetimes,
201        unused_macro_rules,
202        unused_macros,
203        unused_must_use,
204        unused_mut,
205        unused_parens,
206        unused_qualifications,
207        unused_results,
208        unused_unsafe,
209        unused_variables,
210        useless_ptr_null_checks,
211        variant_size_differences,
212        wasm_c_abi,
213        while_true
214    )
215)]
216// If nightly and unstable, allow `incomplete_features` and `unstable_features`
217#![cfg_attr(
218    all(feature = "unstable", nightly),
219    allow(incomplete_features, unstable_features)
220)]
221// If nightly and not unstable, deny `incomplete_features` and `unstable_features`
222#![cfg_attr(
223    all(not(feature = "unstable"), nightly),
224    deny(incomplete_features, unstable_features)
225)]
226// The unstable lints
227#![cfg_attr(
228    all(feature = "unstable", nightly),
229    deny(
230        fuzzy_provenance_casts,
231        lossy_provenance_casts,
232        multiple_supertrait_upcastable,
233        must_not_suspend,
234        non_exhaustive_omitted_patterns,
235        unfulfilled_lint_expectations,
236    )
237)]
238// clippy lints
239#![cfg_attr(nightly, deny(clippy::all, clippy::pedantic))]
240// rustdoc lints
241#![cfg_attr(
242    nightly,
243    deny(
244        rustdoc::bare_urls,
245        rustdoc::broken_intra_doc_links,
246        rustdoc::invalid_codeblock_attributes,
247        rustdoc::invalid_html_tags,
248        rustdoc::missing_crate_level_docs,
249        rustdoc::private_doc_tests,
250        rustdoc::private_intra_doc_links,
251    )
252)]
253#![cfg_attr(
254    all(nightly, feature = "unstable"),
255    deny(rustdoc::missing_doc_code_examples)
256)]
257#![cfg_attr(all(doc, nightly), feature(doc_auto_cfg))]
258#![cfg_attr(all(docsrs, nightly), feature(doc_cfg))]
259#![cfg_attr(coverage_nightly, feature(coverage_attribute))]
260
261mod error;
262mod manager;
263
264// used in doctests
265use anyhow as _;
266use tokio as _;
267
268pub use error::Error;
269pub use manager::Mongodb as MongodbConnectionManager;