pub trait Service:
Send
+ Sync
+ Debug
+ Unpin
+ 'static {
type Reader: Read;
type Writer: Write;
type Lister: List;
type Deleter: Delete;
type Copier: Copy;
// 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, Error>> + MaybeSend;
fn stat(
&self,
ctx: &OperationContext,
path: &str,
args: OpStat,
) -> impl Future<Output = Result<RpStat, Error>> + MaybeSend;
fn read(
&self,
ctx: &OperationContext,
path: &str,
args: OpRead,
) -> Result<Self::Reader, Error>;
fn write(
&self,
ctx: &OperationContext,
path: &str,
args: OpWrite,
) -> Result<Self::Writer, Error>;
fn delete(&self, ctx: &OperationContext) -> Result<Self::Deleter, Error>;
fn list(
&self,
ctx: &OperationContext,
path: &str,
args: OpList,
) -> Result<Self::Lister, Error>;
fn copy(
&self,
ctx: &OperationContext,
from: &str,
to: &str,
args: OpCopy,
opts: OpCopier,
) -> Result<Self::Copier, Error>;
fn rename(
&self,
ctx: &OperationContext,
from: &str,
to: &str,
args: OpRename,
) -> impl Future<Output = Result<RpRename, Error>> + MaybeSend;
fn presign(
&self,
ctx: &OperationContext,
path: &str,
args: OpPresign,
) -> impl Future<Output = Result<RpPresign, Error>> + MaybeSend;
}Expand description
Underlying trait of all storage services.
Every storage backend supported by OpenDAL implements Service. Backends
must implement every operation so unsupported behavior is explicit at the
implementation boundary.
§Operations
- Paths passed into service operations are normalized by the operator.
/means the root path.- Paths ending with
/are directory paths. - Other paths are file paths.
- 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 immutable identity facts for this service.
Sourcefn capability(&self) -> Capability
fn capability(&self) -> Capability
Return the capability of this service stack.
Layers may transform 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, Error>> + MaybeSend
fn create_dir( &self, ctx: &OperationContext, path: &str, args: OpCreateDir, ) -> impl Future<Output = Result<RpCreateDir, Error>> + 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, Error>> + MaybeSend
fn stat( &self, ctx: &OperationContext, path: &str, args: OpStat, ) -> impl Future<Output = Result<RpStat, Error>> + 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, Error>
fn read( &self, ctx: &OperationContext, path: &str, args: OpRead, ) -> Result<Self::Reader, Error>
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, Error>
fn write( &self, ctx: &OperationContext, path: &str, args: OpWrite, ) -> Result<Self::Writer, Error>
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, Error>
fn delete(&self, ctx: &OperationContext) -> Result<Self::Deleter, Error>
Invoke the delete operation.
Requires Capability::delete.
§Behavior
- The returned deleter handles one or more delete requests.
- Deleting a missing path should succeed.
Sourcefn list(
&self,
ctx: &OperationContext,
path: &str,
args: OpList,
) -> Result<Self::Lister, Error>
fn list( &self, ctx: &OperationContext, path: &str, args: OpList, ) -> Result<Self::Lister, Error>
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,
opts: OpCopier,
) -> Result<Self::Copier, Error>
fn copy( &self, ctx: &OperationContext, from: &str, to: &str, args: OpCopy, opts: OpCopier, ) -> Result<Self::Copier, Error>
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.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
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 = ()
fn info(&self) -> ServiceInfo
fn capability(&self) -> Capability
async fn create_dir( &self, _: &OperationContext, _: &str, _: OpCreateDir, ) -> Result<RpCreateDir, Error>
async fn stat( &self, _: &OperationContext, _: &str, _: OpStat, ) -> Result<RpStat, Error>
fn read( &self, _: &OperationContext, _: &str, _: OpRead, ) -> Result<<() as Service>::Reader, Error>
fn write( &self, _: &OperationContext, _: &str, _: OpWrite, ) -> Result<<() as Service>::Writer, Error>
fn delete( &self, _: &OperationContext, ) -> Result<<() as Service>::Deleter, Error>
fn list( &self, _: &OperationContext, _: &str, _: OpList, ) -> Result<<() as Service>::Lister, Error>
fn copy( &self, _: &OperationContext, _: &str, _: &str, _: OpCopy, _: OpCopier, ) -> Result<<() as Service>::Copier, Error>
async fn rename( &self, _: &OperationContext, _: &str, _: &str, _: OpRename, ) -> Result<RpRename, Error>
async fn presign( &self, _: &OperationContext, _: &str, _: OpPresign, ) -> Result<RpPresign, Error>
Source§impl<T> Service for Arc<T>where
T: ServiceDyn + ?Sized,
Service is used behind a Servicer everywhere.
impl<T> Service for Arc<T>where
T: ServiceDyn + ?Sized,
Service is used behind a Servicer everywhere.