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_lints,
60        supertrait_item_shadowing,
61        unqualified_local_imports,
62    )
63)]
64#![cfg_attr(nightly, allow(single_use_lifetimes))]
65#![cfg_attr(
66    nightly,
67    deny(
68        absolute_paths_not_starting_with_crate,
69        ambiguous_glob_imports,
70        ambiguous_glob_reexports,
71        ambiguous_negative_literals,
72        ambiguous_wide_pointer_comparisons,
73        anonymous_parameters,
74        array_into_iter,
75        asm_sub_register,
76        async_fn_in_trait,
77        bad_asm_style,
78        bare_trait_objects,
79        boxed_slice_into_iter,
80        break_with_label_and_loop,
81        clashing_extern_declarations,
82        closure_returning_async_block,
83        coherence_leak_check,
84        confusable_idents,
85        const_evaluatable_unchecked,
86        const_item_mutation,
87        dangling_pointers_from_temporaries,
88        dead_code,
89        dependency_on_unit_never_type_fallback,
90        deprecated,
91        deprecated_in_future,
92        deprecated_safe_2024,
93        deprecated_where_clause_location,
94        deref_into_dyn_supertrait,
95        deref_nullptr,
96        double_negations,
97        drop_bounds,
98        dropping_copy_types,
99        dropping_references,
100        duplicate_macro_attributes,
101        dyn_drop,
102        edition_2024_expr_fragment_specifier,
103        elided_lifetimes_in_paths,
104        ellipsis_inclusive_range_patterns,
105        explicit_outlives_requirements,
106        exported_private_dependencies,
107        ffi_unwind_calls,
108        forbidden_lint_groups,
109        forgetting_copy_types,
110        forgetting_references,
111        for_loops_over_fallibles,
112        function_item_references,
113        hidden_glob_reexports,
114        if_let_rescope,
115        impl_trait_overcaptures,
116        impl_trait_redundant_captures,
117        improper_ctypes,
118        improper_ctypes_definitions,
119        inline_no_sanitize,
120        internal_features,
121        invalid_from_utf8,
122        invalid_macro_export_arguments,
123        invalid_nan_comparisons,
124        invalid_value,
125        irrefutable_let_patterns,
126        keyword_idents_2018,
127        keyword_idents_2024,
128        large_assignments,
129        late_bound_lifetime_arguments,
130        legacy_derive_helpers,
131        let_underscore_drop,
132        macro_use_extern_crate,
133        map_unit_fn,
134        meta_variable_misuse,
135        mismatched_lifetime_syntaxes,
136        missing_abi,
137        missing_copy_implementations,
138        missing_debug_implementations,
139        missing_docs,
140        missing_unsafe_on_extern,
141        mixed_script_confusables,
142        named_arguments_used_positionally,
143        never_type_fallback_flowing_into_unsafe,
144        no_mangle_generic_items,
145        non_ascii_idents,
146        non_camel_case_types,
147        non_contiguous_range_endpoints,
148        non_fmt_panics,
149        non_local_definitions,
150        non_shorthand_field_patterns,
151        non_snake_case,
152        non_upper_case_globals,
153        noop_method_call,
154        opaque_hidden_inferred_bound,
155        out_of_scope_macro_calls,
156        overlapping_range_endpoints,
157        path_statements,
158        private_bounds,
159        private_interfaces,
160        ptr_to_integer_transmute_in_consts,
161        redundant_imports,
162        redundant_lifetimes,
163        redundant_semicolons,
164        refining_impl_trait_internal,
165        refining_impl_trait_reachable,
166        renamed_and_removed_lints,
167        repr_transparent_external_private_fields,
168        rust_2021_incompatible_closure_captures,
169        rust_2021_incompatible_or_patterns,
170        rust_2021_prefixes_incompatible_syntax,
171        rust_2021_prelude_collisions,
172        rust_2024_guarded_string_incompatible_syntax,
173        rust_2024_incompatible_pat,
174        rust_2024_prelude_collisions,
175        self_constructor_from_outer_item,
176        semicolon_in_expressions_from_macros,
177        single_use_lifetimes,
178        special_module_name,
179        stable_features,
180        static_mut_refs,
181        suspicious_double_ref_op,
182        tail_expr_drop_order,
183        trivial_bounds,
184        trivial_casts,
185        trivial_numeric_casts,
186        type_alias_bounds,
187        tyvar_behind_raw_pointer,
188        uncommon_codepoints,
189        unconditional_recursion,
190        uncovered_param_in_projection,
191        unexpected_cfgs,
192        unfulfilled_lint_expectations,
193        ungated_async_fn_track_caller,
194        uninhabited_static,
195        unit_bindings,
196        unknown_lints,
197        unknown_or_malformed_diagnostic_attributes,
198        unnameable_test_items,
199        unnameable_types,
200        unpredictable_function_pointer_comparisons,
201        unreachable_code,
202        unreachable_patterns,
203        unreachable_pub,
204        unsafe_attr_outside_unsafe,
205        unsafe_code,
206        unsafe_op_in_unsafe_fn,
207        unstable_name_collisions,
208        unstable_syntax_pre_expansion,
209        unused_allocation,
210        unused_assignments,
211        unused_associated_type_bounds,
212        unused_attributes,
213        unused_braces,
214        unused_comparisons,
215        unused_crate_dependencies,
216        unused_doc_comments,
217        unused_extern_crates,
218        unused_features,
219        unused_import_braces,
220        unused_imports,
221        unused_labels,
222        unused_lifetimes,
223        unused_macro_rules,
224        unused_macros,
225        unused_must_use,
226        unused_mut,
227        unused_parens,
228        unused_qualifications,
229        unused_results,
230        unused_unsafe,
231        unused_variables,
232        useless_ptr_null_checks,
233        uses_power_alignment,
234        variant_size_differences,
235        while_true,
236    )
237)]
238// If nightly and unstable, allow `incomplete_features` and `unstable_features`
239#![cfg_attr(
240    all(feature = "unstable", nightly),
241    allow(incomplete_features, unstable_features)
242)]
243// If nightly and not unstable, deny `incomplete_features` and `unstable_features`
244#![cfg_attr(
245    all(not(feature = "unstable"), nightly),
246    deny(incomplete_features, unstable_features)
247)]
248// The unstable lints
249#![cfg_attr(
250    all(feature = "unstable", nightly),
251    deny(
252        fuzzy_provenance_casts,
253        lossy_provenance_casts,
254        multiple_supertrait_upcastable,
255        must_not_suspend,
256        non_exhaustive_omitted_patterns,
257        supertrait_item_shadowing_definition,
258        supertrait_item_shadowing_usage,
259        unqualified_local_imports,
260    )
261)]
262// clippy lints
263#![cfg_attr(nightly, deny(clippy::all, clippy::pedantic))]
264// rustdoc lints
265#![cfg_attr(
266    nightly,
267    deny(
268        rustdoc::bare_urls,
269        rustdoc::broken_intra_doc_links,
270        rustdoc::invalid_codeblock_attributes,
271        rustdoc::invalid_html_tags,
272        rustdoc::missing_crate_level_docs,
273        rustdoc::private_doc_tests,
274        rustdoc::private_intra_doc_links,
275    )
276)]
277#![cfg_attr(
278    all(nightly, feature = "unstable"),
279    deny(rustdoc::missing_doc_code_examples)
280)]
281#![cfg_attr(all(docsrs, nightly), feature(doc_cfg))]
282
283mod error;
284mod manager;
285
286// used in doctests
287use anyhow as _;
288use tokio as _;
289
290pub use self::error::Error;
291pub use self::manager::Mongodb as MongodbConnectionManager;