Skip to main content

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