Skip to main content

Service

Trait Service 

Source
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 OperationContext carries layer-composed runtime resources for each operation.

Required Associated Types§

Source

type Reader: Read

Reader returned by read.

Source

type Writer: Write

Writer returned by write.

Source

type Lister: List

Lister returned by list.

Source

type Deleter: Delete

Deleter returned by delete.

Source

type Copier: Copy

Copier returned by copy.

Required Methods§

Source

fn info(&self) -> ServiceInfo

Return immutable identity facts for this service.

Source

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.

Source

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
  • path is a normalized directory path.
  • Creating an existing directory should succeed.
Source

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 mode and content_length.
Source

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
  • path is a normalized file path.
  • Range I/O is handled by the returned reader.
Source

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
  • path is a normalized file path.
Source

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.
Source

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
  • path is a normalized directory path or prefix.
  • Listing a non-existing directory should return an empty stream.
Source

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
  • from and to are normalized file paths.
  • Copying to an existing file should overwrite and truncate it.
Source

fn rename( &self, ctx: &OperationContext, from: &str, to: &str, args: OpRename, ) -> impl Future<Output = Result<RpRename, Error>> + MaybeSend

Invoke the rename operation on the specified from path and to path.

Requires Capability::rename.

§Behavior
  • from and to are normalized file paths.
Source

fn presign( &self, ctx: &OperationContext, path: &str, args: OpPresign, ) -> impl Future<Output = Result<RpPresign, Error>> + MaybeSend

Invoke the presign operation on the specified path.

Requires Capability::presign and the matching presign operation capability.

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.

Source§

type Reader = ()

Source§

type Writer = ()

Source§

type Lister = ()

Source§

type Deleter = ()

Source§

type Copier = ()

Source§

fn info(&self) -> ServiceInfo

Source§

fn capability(&self) -> Capability

Source§

async fn create_dir( &self, _: &OperationContext, _: &str, _: OpCreateDir, ) -> Result<RpCreateDir, Error>

Source§

async fn stat( &self, _: &OperationContext, _: &str, _: OpStat, ) -> Result<RpStat, Error>

Source§

fn read( &self, _: &OperationContext, _: &str, _: OpRead, ) -> Result<<() as Service>::Reader, Error>

Source§

fn write( &self, _: &OperationContext, _: &str, _: OpWrite, ) -> Result<<() as Service>::Writer, Error>

Source§

fn delete( &self, _: &OperationContext, ) -> Result<<() as Service>::Deleter, Error>

Source§

fn list( &self, _: &OperationContext, _: &str, _: OpList, ) -> Result<<() as Service>::Lister, Error>

Source§

fn copy( &self, _: &OperationContext, _: &str, _: &str, _: OpCopy, _: OpCopier, ) -> Result<<() as Service>::Copier, Error>

Source§

async fn rename( &self, _: &OperationContext, _: &str, _: &str, _: OpRename, ) -> Result<RpRename, Error>

Source§

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.

Source§

type Reader = Box<dyn ReadDyn>

Source§

type Writer = Box<dyn WriteDyn>

Source§

type Lister = Box<dyn ListDyn>

Source§

type Deleter = Box<dyn DeleteDyn>

Source§

type Copier = Box<dyn CopyDyn>

Source§

fn info(&self) -> ServiceInfo

Source§

fn capability(&self) -> Capability

Source§

async fn create_dir( &self, ctx: &OperationContext, path: &str, args: OpCreateDir, ) -> Result<RpCreateDir, Error>

Source§

async fn stat( &self, ctx: &OperationContext, path: &str, args: OpStat, ) -> Result<RpStat, Error>

Source§

fn read( &self, ctx: &OperationContext, path: &str, args: OpRead, ) -> Result<Box<dyn ReadDyn>, Error>

Source§

fn write( &self, ctx: &OperationContext, path: &str, args: OpWrite, ) -> Result<Box<dyn WriteDyn>, Error>

Source§

fn delete(&self, ctx: &OperationContext) -> Result<Box<dyn DeleteDyn>, Error>

Source§

fn list( &self, ctx: &OperationContext, path: &str, args: OpList, ) -> Result<Box<dyn ListDyn>, Error>

Source§

fn copy( &self, ctx: &OperationContext, from: &str, to: &str, args: OpCopy, opts: OpCopier, ) -> Result<Box<dyn CopyDyn>, Error>

Source§

async fn rename( &self, ctx: &OperationContext, from: &str, to: &str, args: OpRename, ) -> Result<RpRename, Error>

Source§

async fn presign( &self, ctx: &OperationContext, path: &str, args: OpPresign, ) -> Result<RpPresign, Error>

Implementors§

§

impl Service for FoyerService

§

type Reader = FullReader

§

type Writer = Writer<Box<dyn WriteDyn>>

§

type Lister = Box<dyn ListDyn>

§

type Deleter = Deleter<Box<dyn DeleteDyn>>

§

type Copier = Box<dyn CopyDyn>

§

impl Service for RouteAccessor

§

type Reader = Box<dyn ReadDyn>

§

type Writer = Box<dyn WriteDyn>

§

type Lister = Box<dyn ListDyn>

§

type Deleter = Box<dyn DeleteDyn>

§

type Copier = Box<dyn CopyDyn>