Skip to content

Commit

Permalink
fix some CR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
meteorgan committed Dec 4, 2024
1 parent 477525f commit 3e2bc37
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 23 deletions.
17 changes: 7 additions & 10 deletions core/src/layers/capability_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@
// under the License.

use crate::layers::correctness_check::new_unsupported_args_error;
use crate::raw::{
Access, AccessorInfo, Layer, LayeredAccess, OpDelete, OpList, OpRead, OpStat, OpWrite,
Operation, RpDelete, RpList, RpRead, RpStat, RpWrite,
};
use crate::raw::*;
use std::fmt::{Debug, Formatter};
use std::sync::Arc;

Expand All @@ -42,24 +39,24 @@ use std::sync::Arc;
/// # examples
///
/// ```no_run
/// # use opendal::layers::CapabilityChecker;
/// # use opendal::layers::CapabilityCheckLayer;
/// # use opendal::services;
/// # use opendal::Operator;
/// # use opendal::Result;
/// # use opendal::Scheme;
///
/// # fn main() -> Result<()> {
/// use opendal::layers::CapabilityChecker;
/// use opendal::layers::CapabilityCheckLayer;
/// let _ = Operator::new(services::Memory::default())?
/// .layer(CapabilityChecker)
/// .layer(CapabilityCheckLayer)
/// .finish();
/// Ok(())
/// # }
/// ```
#[derive(Default)]
pub struct CapabilityChecker;
pub struct CapabilityCheckLayer;

impl<A: Access> Layer<A> for CapabilityChecker {
impl<A: Access> Layer<A> for CapabilityCheckLayer {
type LayeredAccess = CapabilityAccessor<A>;

fn layer(&self, inner: A) -> Self::LayeredAccess {
Expand Down Expand Up @@ -313,7 +310,7 @@ mod tests {
fn new_test_operator(capability: Capability) -> Operator {
let srv = MockService { capability };

Operator::from_inner(Arc::new(srv)).layer(CapabilityChecker)
Operator::from_inner(Arc::new(srv)).layer(CapabilityCheckLayer)
}

#[tokio::test]
Expand Down
4 changes: 2 additions & 2 deletions core/src/layers/complete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ impl<A: Access> CompleteAccessor<A> {
return Ok(RpCreateDir::default());
}

unreachable!("with correctness check, we cannot reach here")
return self.inner.create_dir(path, args).await;
}

fn complete_blocking_create_dir(&self, path: &str, args: OpCreateDir) -> Result<RpCreateDir> {
Expand All @@ -151,7 +151,7 @@ impl<A: Access> CompleteAccessor<A> {
return Ok(RpCreateDir::default());
}

unreachable!("with correctness check, we cannot reach here")
return self.inner.blocking_create_dir(path, args);
}

async fn complete_stat(&self, path: &str, args: OpStat) -> Result<RpStat> {
Expand Down
12 changes: 4 additions & 8 deletions core/src/layers/correctness_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@
use std::fmt::{Debug, Formatter};
use std::sync::Arc;

use crate::raw::{
Access, AccessorInfo, Layer, LayeredAccess, OpBatch, OpCopy, OpCreateDir, OpDelete, OpList,
OpPresign, OpRead, OpRename, OpStat, OpWrite, Operation, RpBatch, RpCopy, RpCreateDir,
RpDelete, RpList, RpPresign, RpRead, RpRename, RpStat, RpWrite,
};
use crate::raw::*;
use crate::{Error, ErrorKind};

/// Add a correctness capability check layer for every operation
Expand All @@ -40,9 +36,9 @@ use crate::{Error, ErrorKind};
/// for example, when calling `write_with_append`, but `append` is not supported by the underlying
/// service, an `Unsupported` error is returned. without this check, undesired data may be written.
#[derive(Default)]
pub struct CorrectnessChecker;
pub struct CorrectnessCheckLayer;

impl<A: Access> Layer<A> for CorrectnessChecker {
impl<A: Access> Layer<A> for CorrectnessCheckLayer {
type LayeredAccess = CorrectnessAccessor<A>;

fn layer(&self, inner: A) -> Self::LayeredAccess {
Expand Down Expand Up @@ -427,7 +423,7 @@ mod tests {
fn new_test_operator(capability: Capability) -> Operator {
let srv = MockService { capability };

Operator::from_inner(Arc::new(srv)).layer(CorrectnessChecker)
Operator::from_inner(Arc::new(srv)).layer(CorrectnessCheckLayer)
}

#[tokio::test]
Expand Down
4 changes: 2 additions & 2 deletions core/src/layers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,6 @@ pub use self::dtrace::DtraceLayer;
pub mod observe;

mod correctness_check;
pub(crate) use correctness_check::CorrectnessChecker;
pub(crate) use correctness_check::CorrectnessCheckLayer;
mod capability_check;
pub use capability_check::CapabilityChecker;
pub use capability_check::CapabilityCheckLayer;
2 changes: 1 addition & 1 deletion core/src/types/operator/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ impl<A: Access> OperatorBuilder<A> {
OperatorBuilder { accessor }
.layer(ErrorContextLayer)
.layer(CompleteLayer)
.layer(CorrectnessChecker)
.layer(CorrectnessCheckLayer)
}

/// Create a new layer with static dispatch.
Expand Down

0 comments on commit 3e2bc37

Please sign in to comment.