pub trait Service:
Send
+ Sync
+ Debug
+ Unpin
+ 'static {
type Reader: Read;
type Writer: Write;
type Lister: List;
type Deleter: Delete;
type Copier: Copy;
type Composer: Compose;
Show 13 methods
// Required methods
fn info(&self) -> ServiceInfo;
fn capability(&self) -> Capability;
fn create_dir(
&self,
ctx: &OperationContext,
path: &str,
args: OpCreateDir,
) -> impl Future<Output = Result<RpCreateDir>> + MaybeSend;
fn stat(
&self,
ctx: &OperationContext,
path: &str,
args: OpStat,
) -> impl Future<Output = Result<RpStat>> + MaybeSend;
fn read(
&self,
ctx: &OperationContext,
path: &str,
args: OpRead,
) -> Result<Self::Reader>;
fn write(
&self,
ctx: &OperationContext,
path: &str,
args: OpWrite,
) -> Result<Self::Writer>;
fn delete(&self, ctx: &OperationContext) -> Result<Self::Deleter>;
fn list(
&self,
ctx: &OperationContext,
path: &str,
args: OpList,
) -> Result<Self::Lister>;
fn copy(
&self,
ctx: &OperationContext,
from: &str,
to: &str,
args: OpCopy,
) -> Result<Self::Copier>;
fn rename(
&self,
ctx: &OperationContext,
from: &str,
to: &str,
args: OpRename,
) -> impl Future<Output = Result<RpRename>> + MaybeSend;
fn presign(
&self,
ctx: &OperationContext,
path: &str,
args: OpPresign,
) -> impl Future<Output = Result<RpPresign>> + MaybeSend;
// Provided methods
fn compose(
&self,
_ctx: &OperationContext,
_to: &str,
_args: OpCompose,
) -> Result<Self::Composer> { ... }
fn restore(
&self,
_ctx: &OperationContext,
_path: &str,
_args: OpRestore,
) -> impl Future<Output = Result<RpRestore>> + MaybeSend { ... }
}Expand description
Foundational trait for storage services.
Every storage service (or backend) in OpenDAL implements Service. Services
and layers must implement every operation in this trait and declare their
capabilities. This allows callers to detect unsupported operations.
§Operations
- An operator normalizes paths before passing them to a
Service. Relative to the configuredroot:/represents the root.- A path ending with
/represents a directory. - Any other path represents a file.
- Services report their supported operation set through
Service::capability. - The
OperationContextcarries layer-composed runtime resources for each operation.
Required Associated Types§
Required Methods§
Sourcefn info(&self) -> ServiceInfo
fn info(&self) -> ServiceInfo
Return the immutable identity and configuration for this service.
Sourcefn capability(&self) -> Capability
fn capability(&self) -> Capability
Return the capability of this service stack.
Layers may affect a service’s capabilities, so callers should use this value for the current stack instead of assuming the backend’s native capability.
Sourcefn create_dir(
&self,
ctx: &OperationContext,
path: &str,
args: OpCreateDir,
) -> impl Future<Output = Result<RpCreateDir>> + MaybeSend
fn create_dir( &self, ctx: &OperationContext, path: &str, args: OpCreateDir, ) -> impl Future<Output = Result<RpCreateDir>> + MaybeSend
Invoke the create operation on the specified path.
Requires Capability::create_dir.
§Behavior
pathis a normalized directory path.- Creating an existing directory should succeed.
Sourcefn stat(
&self,
ctx: &OperationContext,
path: &str,
args: OpStat,
) -> impl Future<Output = Result<RpStat>> + MaybeSend
fn stat( &self, ctx: &OperationContext, path: &str, args: OpStat, ) -> impl Future<Output = Result<RpStat>> + MaybeSend
Invoke the stat operation on the specified path.
Requires Capability::stat.
§Behavior
/means the service root.- A path ending with
/stats a directory. - Returned metadata must set
modeandcontent_length.
Sourcefn read(
&self,
ctx: &OperationContext,
path: &str,
args: OpRead,
) -> Result<Self::Reader>
fn read( &self, ctx: &OperationContext, path: &str, args: OpRead, ) -> Result<Self::Reader>
Invoke the read operation on the specified path.
Requires Capability::read.
§Behavior
pathis a normalized file path.- Range I/O is handled by the returned reader.
Sourcefn write(
&self,
ctx: &OperationContext,
path: &str,
args: OpWrite,
) -> Result<Self::Writer>
fn write( &self, ctx: &OperationContext, path: &str, args: OpWrite, ) -> Result<Self::Writer>
Invoke the write operation on the specified path.
Requires Capability::write.
§Behavior
pathis a normalized file path.
Sourcefn delete(&self, ctx: &OperationContext) -> Result<Self::Deleter>
fn delete(&self, ctx: &OperationContext) -> Result<Self::Deleter>
Invoke the delete operation.
Requires Capability::delete.
§Behavior
- The returned deleter handles one or more delete requests.
- Deleting a missing path should succeed unless a condition requires a live target.
Sourcefn list(
&self,
ctx: &OperationContext,
path: &str,
args: OpList,
) -> Result<Self::Lister>
fn list( &self, ctx: &OperationContext, path: &str, args: OpList, ) -> Result<Self::Lister>
Invoke the list operation on the specified path.
Requires Capability::list.
§Behavior
pathis a normalized directory path or prefix.- Listing a non-existing directory should return an empty stream.
Sourcefn copy(
&self,
ctx: &OperationContext,
from: &str,
to: &str,
args: OpCopy,
) -> Result<Self::Copier>
fn copy( &self, ctx: &OperationContext, from: &str, to: &str, args: OpCopy, ) -> Result<Self::Copier>
Invoke the copy operation on the specified from path and to path.
Requires Capability::copy.
§Behavior
fromandtoare normalized file paths.- Copying to an existing file should overwrite and truncate it.
Sourcefn rename(
&self,
ctx: &OperationContext,
from: &str,
to: &str,
args: OpRename,
) -> impl Future<Output = Result<RpRename>> + MaybeSend
fn rename( &self, ctx: &OperationContext, from: &str, to: &str, args: OpRename, ) -> impl Future<Output = Result<RpRename>> + MaybeSend
Invoke the rename operation on the specified from path and to path.
Requires Capability::rename.
§Behavior
fromandtoare normalized file paths.
Sourcefn presign(
&self,
ctx: &OperationContext,
path: &str,
args: OpPresign,
) -> impl Future<Output = Result<RpPresign>> + MaybeSend
fn presign( &self, ctx: &OperationContext, path: &str, args: OpPresign, ) -> impl Future<Output = Result<RpPresign>> + MaybeSend
Invoke the presign operation on the specified path.
Requires Capability::presign and the matching presign operation
capability.
Provided Methods§
Sourcefn compose(
&self,
_ctx: &OperationContext,
_to: &str,
_args: OpCompose,
) -> Result<Self::Composer>
fn compose( &self, _ctx: &OperationContext, _to: &str, _args: OpCompose, ) -> Result<Self::Composer>
Invoke the compose operation for the specified destination path.
Requires Capability::compose.
Sourcefn restore(
&self,
_ctx: &OperationContext,
_path: &str,
_args: OpRestore,
) -> impl Future<Output = Result<RpRestore>> + MaybeSend
fn restore( &self, _ctx: &OperationContext, _path: &str, _args: OpRestore, ) -> impl Future<Output = Result<RpRestore>> + MaybeSend
Invoke the restore operation on the specified path.
Requires Capability::restore.
§Behavior
pathis a normalized file path.- Without a version, restore reverses the latest recoverable deletion state.
- With a version, restore promotes that historical version to the current version.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl Service for ()
Dummy implementation of service.
impl Service for ()
Dummy implementation of service.
type Reader = ()
type Writer = ()
type Lister = ()
type Deleter = ()
type Copier = ()
type Composer = ()
fn info(&self) -> ServiceInfo
fn capability(&self) -> Capability
async fn create_dir( &self, _: &OperationContext, _: &str, _: OpCreateDir, ) -> Result<RpCreateDir>
async fn stat(&self, _: &OperationContext, _: &str, _: OpStat) -> Result<RpStat>
fn read(&self, _: &OperationContext, _: &str, _: OpRead) -> Result<Self::Reader>
fn write( &self, _: &OperationContext, _: &str, _: OpWrite, ) -> Result<Self::Writer>
fn delete(&self, _: &OperationContext) -> Result<Self::Deleter>
fn list(&self, _: &OperationContext, _: &str, _: OpList) -> Result<Self::Lister>
fn copy( &self, _: &OperationContext, _: &str, _: &str, _: OpCopy, ) -> Result<Self::Copier>
async fn rename( &self, _: &OperationContext, _: &str, _: &str, _: OpRename, ) -> Result<RpRename>
async fn presign( &self, _: &OperationContext, _: &str, _: OpPresign, ) -> Result<RpPresign>
Source§impl<T: ServiceDyn + ?Sized> Service for Arc<T>
Implement Service for type-erased services so they use the same API.
impl<T: ServiceDyn + ?Sized> Service for Arc<T>
Implement Service for type-erased services so they use the same API.