opendal/
lib.rs

1// Licensed to the Apache Software Foundation (ASF) under one
2// or more contributor license agreements.  See the NOTICE file
3// distributed with this work for additional information
4// regarding copyright ownership.  The ASF licenses this file
5// to you under the Apache License, Version 2.0 (the
6// "License"); you may not use this file except in compliance
7// with the License.  You may obtain a copy of the License at
8//
9//   http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing,
12// software distributed under the License is distributed on an
13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14// KIND, either express or implied.  See the License for the
15// specific language governing permissions and limitations
16// under the License.
17
18#![doc(
19    html_logo_url = "https://raw.githubusercontent.com/apache/opendal/main/website/static/img/logo.svg"
20)]
21#![cfg_attr(docsrs, feature(doc_auto_cfg))]
22
23//! Apache OpenDALâ„¢ is an Open Data Access Layer that enables seamless interaction with diverse storage services.
24//!
25//! OpenDAL's development is guided by its vision of **One Layer, All Storage** and its core principles: **Open Community**, **Solid Foundation**, **Fast Access**, **Object Storage First**, and **Extensible Architecture**. Read the explained vision at [OpenDAL Vision](https://opendal.apache.org/vision).
26//!
27//! # Quick Start
28//!
29//! OpenDAL's API entry points are [`Operator`] and [`BlockingOperator`]. All
30//! public APIs are accessible through the operator. To utilize OpenDAL, you
31//! need to:
32//!
33//! - [Init a service](#init-a-service)
34//! - [Compose layers](#compose-layers)
35//! - [Use operator](#use-operator)
36//!
37//! ## Init a service
38//!
39//! The first step is to pick a service and init it with a builder. All supported
40//! services could be found at [`services`].
41//!
42//! Let's take [`services::S3`] as an example:
43//!
44//! ```no_run
45//! use opendal::services;
46//! use opendal::Operator;
47//! use opendal::Result;
48//!
49//! fn main() -> Result<()> {
50//!     // Pick a builder and configure it.
51//!     let mut builder = services::S3::default().bucket("test");
52//!
53//!     // Init an operator
54//!     let op = Operator::new(builder)?.finish();
55//!     Ok(())
56//! }
57//! ```
58//!
59//! ## Compose layers
60//!
61//! The next setup is to compose layers. Layers are modules that provide extra
62//! features for every operation. All builtin layers could be found at [`layers`].
63//!
64//! Let's use [`layers::LoggingLayer`] as an example; this layer adds logging to
65//! every operation that OpenDAL performs.
66//!
67//! ```no_run
68//! use opendal::layers::LoggingLayer;
69//! use opendal::services;
70//! use opendal::Operator;
71//! use opendal::Result;
72//!
73//! #[tokio::main]
74//! async fn main() -> Result<()> {
75//!     // Pick a builder and configure it.
76//!     let mut builder = services::S3::default().bucket("test");
77//!
78//!     // Init an operator
79//!     let op = Operator::new(builder)?
80//!         // Init with logging layer enabled.
81//!         .layer(LoggingLayer::default())
82//!         .finish();
83//!
84//!     Ok(())
85//! }
86//! ```
87//!
88//! ## Use operator
89//!
90//! The final step is to use the operator. OpenDAL supports both async [`Operator`]
91//! and blocking [`BlockingOperator`]. Please pick the one that fits your use case.
92//!
93//! Every Operator API follows the same pattern, take `read` as an example:
94//!
95//! - `read`: Execute a read operation.
96//! - `read_with`: Execute a read operation with additional options, like `range` and `if_match`.
97//! - `reader`: Create a reader for streaming data, enabling flexible access.
98//! - `reader_with`: Create a reader with advanced options.
99//!
100//! ```no_run
101//! use opendal::layers::LoggingLayer;
102//! use opendal::services;
103//! use opendal::Operator;
104//! use opendal::Result;
105//!
106//! #[tokio::main]
107//! async fn main() -> Result<()> {
108//!     // Pick a builder and configure it.
109//!     let mut builder = services::S3::default().bucket("test");
110//!
111//!     // Init an operator
112//!     let op = Operator::new(builder)?
113//!         // Init with logging layer enabled.
114//!         .layer(LoggingLayer::default())
115//!         .finish();
116//!
117//!     // Fetch this file's metadata
118//!     let meta = op.stat("hello.txt").await?;
119//!     let length = meta.content_length();
120//!
121//!     // Read data from `hello.txt` with range `0..1024`.
122//!     let bs = op.read_with("hello.txt").range(0..1024).await?;
123//!
124//!     Ok(())
125//! }
126//! ```
127
128// Make sure all our public APIs have docs.
129#![warn(missing_docs)]
130
131// Private module with public types, they will be accessed via `opendal::Xxxx`
132mod types;
133pub use types::*;
134
135// Public modules, they will be accessed like `opendal::layers::Xxxx`
136#[cfg(docsrs)]
137pub mod docs;
138pub mod layers;
139pub mod raw;
140pub mod services;
141
142#[cfg(test)]
143mod tests {
144    use std::mem::size_of;
145
146    use super::*;
147    /// This is not a real test case.
148    ///
149    /// We assert our public structs here to make sure we don't introduce
150    /// unexpected struct/enum size change.
151    #[test]
152    fn assert_size() {
153        assert_eq!(16, size_of::<Operator>());
154        assert_eq!(320, size_of::<Entry>());
155        assert_eq!(296, size_of::<Metadata>());
156        assert_eq!(1, size_of::<EntryMode>());
157        assert_eq!(24, size_of::<Scheme>());
158    }
159
160    trait AssertSendSync: Send + Sync {}
161    impl AssertSendSync for Entry {}
162    impl AssertSendSync for Capability {}
163    impl AssertSendSync for Error {}
164    impl AssertSendSync for Reader {}
165    impl AssertSendSync for Writer {}
166    impl AssertSendSync for Lister {}
167    impl AssertSendSync for Operator {}
168    impl AssertSendSync for BlockingReader {}
169    impl AssertSendSync for BlockingWriter {}
170    impl AssertSendSync for BlockingLister {}
171    impl AssertSendSync for BlockingOperator {}
172
173    /// This is used to make sure our public API implement Send + Sync
174    #[test]
175    fn test_trait() {
176        let _: Box<dyn AssertSendSync> = Box::new(Capability::default());
177    }
178}