Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Don't expose ops structs to users directly #1303

Merged
merged 1 commit into from
Feb 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/layers/chaos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use futures::FutureExt;
use rand::prelude::*;
use rand::rngs::StdRng;

use crate::ops::*;
use crate::raw::*;
use crate::*;

Expand Down
1 change: 1 addition & 0 deletions src/layers/complete_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use std::task::Poll;

use async_trait::async_trait;

use crate::ops::*;
use crate::raw::*;
use crate::*;

Expand Down
1 change: 1 addition & 0 deletions src/layers/concurrent_limit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use bytes::Bytes;
use tokio::sync::OwnedSemaphorePermit;
use tokio::sync::Semaphore;

use crate::ops::*;
use crate::raw::*;
use crate::*;

Expand Down
1 change: 1 addition & 0 deletions src/layers/error_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use std::fmt::Formatter;
use async_trait::async_trait;
use futures::TryFutureExt;

use crate::ops::*;
use crate::raw::*;
use crate::*;

Expand Down
1 change: 1 addition & 0 deletions src/layers/immutable_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use std::mem;
use async_trait::async_trait;

use crate::object::*;
use crate::ops::*;
use crate::raw::*;
use crate::*;

Expand Down
1 change: 1 addition & 0 deletions src/layers/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use log::log;
use log::trace;
use log::Level;

use crate::ops::*;
use crate::raw::*;
use crate::*;

Expand Down
1 change: 1 addition & 0 deletions src/layers/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ use metrics::register_histogram;
use metrics::Counter;
use metrics::Histogram;

use crate::ops::*;
use crate::raw::*;
use crate::*;

Expand Down
10 changes: 6 additions & 4 deletions src/layers/retry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use futures::ready;
use futures::FutureExt;
use log::warn;

use crate::ops::*;
use crate::raw::*;
use crate::*;

Expand Down Expand Up @@ -640,16 +641,17 @@ impl<R: output::BlockingRead> output::BlockingRead for RetryReader<R> {

#[cfg(test)]
mod tests {
use anyhow::anyhow;
use async_trait::async_trait;
use bytes::Bytes;
use futures::AsyncReadExt;
use std::io;
use std::sync::Arc;
use std::sync::Mutex;
use std::task::Context;
use std::task::Poll;

use anyhow::anyhow;
use async_trait::async_trait;
use bytes::Bytes;
use futures::AsyncReadExt;

use super::*;

#[derive(Debug, Clone, Default)]
Expand Down
1 change: 1 addition & 0 deletions src/layers/tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use futures::AsyncRead;
use futures::FutureExt;
use tracing::Span;

use crate::ops::*;
use crate::raw::*;
use crate::*;

Expand Down
1 change: 1 addition & 0 deletions src/layers/type_eraser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use std::fmt::Formatter;

use async_trait::async_trait;

use crate::ops::*;
use crate::raw::*;
use crate::*;

Expand Down
15 changes: 1 addition & 14 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,24 +92,11 @@ pub use error::Error;
pub use error::ErrorKind;
pub use error::Result;

mod ops;
pub use ops::OpAbortMultipart;
pub use ops::OpCompleteMultipart;
pub use ops::OpCreate;
pub use ops::OpCreateMultipart;
pub use ops::OpDelete;
pub use ops::OpList;
pub use ops::OpPresign;
pub use ops::OpRead;
pub use ops::OpStat;
pub use ops::OpWrite;
pub use ops::OpWriteMultipart;
pub use ops::PresignOperation;

// Public modules, they will be accessed like `opendal::layers::Xxxx`
#[cfg(feature = "docs")]
pub mod docs;
pub mod layers;
pub mod ops;
pub mod raw;
pub mod services;

Expand Down
2 changes: 1 addition & 1 deletion src/object/blocking_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ use parking_lot::Mutex;

use crate::error::Error;
use crate::error::Result;
use crate::ops::OpRead;
use crate::raw::*;
use crate::ErrorKind;
use crate::ObjectMetadata;
use crate::OpRead;

/// BlockingObjectReader is the public API for users.
pub struct BlockingObjectReader {
Expand Down
1 change: 1 addition & 0 deletions src/object/multipart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use futures::io::Cursor;
use time::Duration;

use crate::ops::*;
use crate::raw::*;
use crate::*;

Expand Down
14 changes: 5 additions & 9 deletions src/object/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use tokio::io::ReadBuf;
use super::BlockingObjectLister;
use super::BlockingObjectReader;
use super::ObjectLister;
use crate::ops::*;
use crate::raw::*;
use crate::*;

Expand Down Expand Up @@ -716,12 +717,10 @@ impl Object {
/// # Examples
///
/// ```no_run
/// # use opendal::OpWrite;
/// # use std::io::Result;
/// # use opendal::Operator;
/// # use futures::StreamExt;
/// # use futures::SinkExt;
/// use bytes::Bytes;
/// use opendal::ops::OpWrite;
///
/// # #[tokio::main]
/// # async fn test(op: Operator) -> Result<()> {
Expand Down Expand Up @@ -791,13 +790,10 @@ impl Object {
/// # Examples
///
/// ```no_run
/// # use opendal::OpWrite;
/// # use std::io::Result;
/// # use opendal::Result;
/// # use opendal::Operator;
/// # use futures::StreamExt;
/// # use futures::SinkExt;
/// # use opendal::Scheme;
/// use bytes::Bytes;
/// use opendal::ops::OpWrite;
///
/// # async fn test(op: Operator) -> Result<()> {
/// let o = op.object("hello.txt");
Expand Down Expand Up @@ -1437,7 +1433,7 @@ impl Object {
/// ```no_run
/// use anyhow::Result;
/// use futures::io;
/// use opendal::OpWrite;
/// use opendal::ops::OpWrite;
/// use opendal::Operator;
/// use time::Duration;
///
Expand Down
2 changes: 1 addition & 1 deletion src/object/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ use futures::AsyncSeek;
use futures::Stream;

use crate::error::Result;
use crate::ops::OpRead;
use crate::raw::*;
use crate::OpRead;

/// ObjectReader is the public API for users.
///
Expand Down
4 changes: 4 additions & 0 deletions src/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//! Ops provides the operation args struct like [`OpRead`] for user.
//!
//! By using ops, users can add more context for operation.

use time::Duration;

use crate::raw::*;
Expand Down
1 change: 1 addition & 0 deletions src/raw/accessor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use async_trait::async_trait;
use flagset::flags;
use flagset::FlagSet;

use crate::ops::*;
use crate::raw::*;
use crate::*;

Expand Down
1 change: 1 addition & 0 deletions src/raw/adapters/kv/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use async_trait::async_trait;
use futures::AsyncReadExt;

use super::Adapter;
use crate::ops::*;
use crate::raw::*;
use crate::*;

Expand Down
1 change: 1 addition & 0 deletions src/raw/io/output/into_reader/by_range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use futures::future::BoxFuture;
use futures::ready;
use tokio::io::ReadBuf;

use crate::ops::*;
use crate::raw::*;
use crate::*;

Expand Down
1 change: 1 addition & 0 deletions src/raw/io/walk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use std::mem;
use async_trait::async_trait;

use crate::object::*;
use crate::ops::*;
use crate::raw::*;
use crate::*;

Expand Down
2 changes: 2 additions & 0 deletions src/raw/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use std::fmt::Debug;

use async_trait::async_trait;

use crate::ops::*;
use crate::raw::*;
use crate::*;

Expand All @@ -42,6 +43,7 @@ use crate::*;
/// use std::sync::Arc;
///
/// use async_trait::async_trait;
/// use opendal::ops::*;
/// use opendal::raw::*;
/// use opendal::*;
///
Expand Down
1 change: 1 addition & 0 deletions src/services/azblob/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ use reqsign::AzureStorageSigner;
use super::dir_stream::DirStream;
use super::error::parse_error;
use crate::object::ObjectMetadata;
use crate::ops::*;
use crate::raw::*;
use crate::*;

Expand Down
1 change: 1 addition & 0 deletions src/services/azdfs/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use reqsign::AzureStorageSigner;
use super::dir_stream::DirStream;
use super::error::parse_error;
use crate::object::ObjectMetadata;
use crate::ops::*;
use crate::raw::*;
use crate::*;

Expand Down
4 changes: 3 additions & 1 deletion src/services/fs/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ use std::cmp::min;
use std::collections::HashMap;
use std::io;
use std::io::SeekFrom;
use std::path::{Path, PathBuf};
use std::path::Path;
use std::path::PathBuf;

use async_compat::Compat;
use async_trait::async_trait;
Expand All @@ -29,6 +30,7 @@ use super::dir_stream::BlockingDirPager;
use super::dir_stream::DirPager;
use super::error::parse_io_error;
use crate::object::*;
use crate::ops::*;
use crate::raw::*;
use crate::*;

Expand Down
4 changes: 3 additions & 1 deletion src/services/fs/dir_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::path::Path;
use std::path::PathBuf;

use async_trait::async_trait;
use std::path::{Path, PathBuf};

use super::error::parse_io_error;
use crate::raw::*;
Expand Down
1 change: 1 addition & 0 deletions src/services/ftp/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ use tokio::sync::OnceCell;
use super::dir_stream::DirStream;
use super::dir_stream::ReadDir;
use super::util::FtpReader;
use crate::ops::*;
use crate::raw::*;
use crate::*;

Expand Down
1 change: 1 addition & 0 deletions src/services/gcs/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ use super::dir_stream::DirStream;
use super::error::parse_error;
use super::error::parse_json_deserialize_error;
use super::uri::percent_encode_path;
use crate::ops::*;
use crate::raw::*;
use crate::*;

Expand Down
1 change: 1 addition & 0 deletions src/services/ghac/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use serde::Deserialize;
use serde::Serialize;

use super::error::parse_error;
use crate::ops::*;
use crate::raw::*;
use crate::*;

Expand Down
1 change: 1 addition & 0 deletions src/services/hdfs/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use time::OffsetDateTime;

use super::dir_stream::DirStream;
use super::error::parse_io_error;
use crate::ops::*;
use crate::raw::*;
use crate::*;

Expand Down
1 change: 1 addition & 0 deletions src/services/http/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use http::StatusCode;
use log::debug;

use super::error::parse_error;
use crate::ops::*;
use crate::raw::*;
use crate::*;

Expand Down
1 change: 1 addition & 0 deletions src/services/ipfs/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use prost::Message;

use super::error::parse_error;
use super::ipld::PBNode;
use crate::ops::*;
use crate::raw::*;
use crate::*;

Expand Down
1 change: 1 addition & 0 deletions src/services/ipmfs/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use serde::Deserialize;
use super::dir_stream::DirStream;
use super::error::parse_error;
use super::error::parse_json_deserialize_error;
use crate::ops::*;
use crate::raw::*;
use crate::*;

Expand Down
1 change: 1 addition & 0 deletions src/services/obs/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use reqsign::HuaweicloudObsSigner;

use super::dir_stream::DirStream;
use super::error::parse_error;
use crate::ops::*;
use crate::raw::*;
use crate::*;

Expand Down
1 change: 1 addition & 0 deletions src/services/oss/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use reqsign::AliyunOssSigner;

use super::dir_stream::DirStream;
use super::error::parse_error;
use crate::ops::*;
use crate::raw::*;
use crate::*;

Expand Down
Loading