remi_gridfs/
lib.rs

1// ๐Ÿปโ€โ„๏ธ๐Ÿงถ remi-rs: Asynchronous Rust crate to handle communication between applications and object storage providers
2// Copyright (c) 2022-2025 Noelware, LLC. <team@noelware.org>
3//
4// Permission is hereby granted, free of charge, to any person obtaining a copy
5// of this software and associated documentation files (the "Software"), to deal
6// in the Software without restriction, including without limitation the rights
7// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8// copies of the Software, and to permit persons to whom the Software is
9// furnished to do so, subject to the following conditions:
10//
11// The above copyright notice and this permission notice shall be included in all
12// copies or substantial portions of the Software.
13//
14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20// SOFTWARE.
21
22//! # ๐Ÿปโ€โ„๏ธ๐Ÿงถ `remi_gridfs`
23//! This crate is an official implementation of [`remi::StorageService`] with the official
24//! [`mongodb`] crate by the MongoDB Rust Driver team.
25//!
26//! [`remi::StorageSerive`]: https://docs.rs/remi/*/remi/trait.StorageService.html
27//! [`mongodb`]: https://docs.rs/mongodb
28//!
29//! ## Example
30//! ```rust,no_run
31//! // Cargo.toml:
32//! //
33//! // [dependencies]
34//! // remi = "^0"
35//! // remi-gridfs = { version = "^0", features = ["export-crates"] }
36//! // tokio = { version = "^1", features = ["full"] }
37//!
38//! use remi_gridfs::{StorageService, StorageConfig, mongodb};
39//! use remi::{StorageService as _, UploadRequest};
40//!
41//! #[tokio::main]
42//! async fn main() {
43//!     let storage = StorageService::from_conn_string("mongodb://localhost:27017", StorageConfig {
44//!         bucket: "my-bucket".into(),
45//!
46//!         ..Default::default()
47//!     }).await.unwrap();
48//!
49//!     // Initialize the container. This will:
50//!     //
51//!     // * create the `my-bucket` GridFS bucket if it doesn't exist
52//!     storage.init().await.unwrap();
53//!
54//!     // Now we can upload files to GridFS.
55//!
56//!     // We define a `UploadRequest`, which will set the content type to `text/plain` and set the
57//!     // contents of `weow.txt` to `weow fluff`.
58//!     let upload = UploadRequest::default()
59//!         .with_content_type(Some("text/plain"))
60//!         .with_data("weow fluff");
61//!
62//!     // Let's upload it!
63//!     storage.upload("weow.txt", upload).await.unwrap();
64//!
65//!     // Let's check if it exists! This `assert!` will panic if it failed
66//!     // to upload.
67//!     assert!(storage.exists("weow.txt").await.unwrap());
68//! }
69//! ```
70//!
71//! ## Crate Features
72//! | Crate Features  | Description                                                                          | Enabled by default? |
73//! | :-------------- | :----------------------------------------------------------------------------------- | ------------------- |
74//! | `export-crates` | Exports all the used MongoDB crates as a module called `mongodb`                     | No.                |
75//! | `unstable`      | Tap into unstable features from `remi_gridfs` and the `remi` crate.                  | No.                 |
76//! | [`tracing`]     | Enables the use of [`tracing::instrument`] and emit events for actions by the crate. | No.                 |
77//! | [`serde`]       | Enables the use of **serde** in `StorageConfig`                                      | No.                 |
78//! | [`log`]         | Emits log records for actions by the crate                                           | No.                 | | Crate Features  | Description                                                                          | Enabled by default? |
79//!
80//! [`tracing::instrument`]: https://docs.rs/tracing/*/tracing/attr.instrument.html
81//! [`tracing`]: https://crates.io/crates/tracing
82//! [`serde`]: https://serde.rs
83//! [`log`]: https://crates.io/crates/log
84
85#![doc(html_logo_url = "https://cdn.floofy.dev/images/trans.png")]
86#![doc(html_favicon_url = "https://cdn.floofy.dev/images/trans.png")]
87#![cfg_attr(any(noeldoc, docsrs), feature(doc_cfg))]
88
89mod config;
90mod service;
91
92pub use config::*;
93pub use service::*;
94
95/// Exports the [`mongodb`] crate without specifying the dependency yourself.
96#[cfg(feature = "export-crates")]
97#[cfg_attr(any(noeldoc, docsrs), doc(cfg(feature = "export-crates")))]
98pub use mongodb;