remi_fs/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_fs`
23//! This crate is an official implementation of [`remi::StorageService`] that uses
24//! the local filesystem for operations.
25//!
26//! [`remi::StorageService`]: https://docs.rs/remi/*/remi/trait.StorageService.html
27//!
28//! ## Example
29//! ```rust,no_run
30//! // Cargo.toml:
31//! //
32//! // [dependencies]
33//! // remi = "^0"
34//! // remi-fs = "^0"
35//! // tokio = { version = "^1", features = ["full"] }
36//!
37//! use remi_fs::{StorageService, StorageConfig};
38//! use remi::{StorageService as _, UploadRequest};
39//!
40//! #[tokio::main]
41//! async fn main() {
42//! // Initialize a `StorageService` that uses your local filesystem for storing files.
43//! let storage = StorageService::new("./data");
44//!
45//! // Next, we will run the `init` function which will create
46//! // the ./data directory if it doesn't exist already.
47//! storage.init().await.unwrap();
48//!
49//! // We define a `UploadRequest`, which will set the content type to `text/plain` and set the
50//! // contents of `weow.txt` to `weow fluff`.
51//! let upload = UploadRequest::default()
52//! .with_content_type(Some("text/plain"))
53//! .with_data("weow fluff");
54//!
55//! // Let's upload it!
56//! storage.upload("./weow.txt", upload).await.unwrap();
57//!
58//! // Let's check if it exists! This `assert!` will panic if it failed
59//! // to upload.
60//! assert!(storage.exists("./weow.txt").await.unwrap());
61//! }
62//! ```
63//!
64//! ## Crate Features
65//! | Crate Features | Description | Enabled by default? |
66//! | :---------------- | :------------------------------------------------------------------------------------- | -------------------- |
67//! | `unstable` | Tap into unstable features from `remi_fs` and the `remi` crate. | No. |
68//! | [`serde_yaml_ng`] | Allows to detect YAML documents with the [`serde_yaml_ng`] crate. | No. |
69//! | [`serde_json`] | Uses the [`serde_json`] crate to detect JSON documents and return `application/json` | No. |
70//! | [`file-format`] | Uses the [`file-format`] crate to find media types on any external datatype. | Yes. |
71//! | [`tracing`] | Enables the use of [`tracing::instrument`] and emit events for actions by the crate. | No. |
72//! | [`infer`] | Uses the [`infer`] crate to infer external datatypes and map them to their media type. | Yes. |
73//! | [`serde`] | Enables the use of **serde** in `StorageConfig` | No. |
74//! | [`log`] | Emits log records for actions by the crate | No. |
75//!
76//! [`tracing::instrument`]: https://docs.rs/tracing/*/tracing/attr.instrument.html
77//! [`serde_yaml_ng`]: https://crates.io/crates/serde_yaml_ng
78//! [`file-format`]: https://crates.io/crates/file-format
79//! [`serde_json`]: https://crates.io/crates/serde_json
80//! [`tracing`]: https://crates.io/crates/tracing
81//! [`infer`]: https://crates.io/crates/infer
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 content_type;
91mod service;
92
93pub use config::*;
94pub use content_type::*;
95pub use service::*;