pub trait AsyncSliceWriter: Sized {
    type WriteAtFuture<'a>: Future<Output = Result<(), Error>> + 'a
       where Self: 'a;
    type WriteBytesAtFuture<'a>: Future<Output = Result<(), Error>> + 'a
       where Self: 'a;
    type SetLenFuture<'a>: Future<Output = Result<(), Error>> + 'a
       where Self: 'a;
    type SyncFuture<'a>: Future<Output = Result<(), Error>> + 'a
       where Self: 'a;

    // Required methods
    fn write_at(&mut self, offset: u64, data: &[u8]) -> Self::WriteAtFuture<'_>;
    fn write_bytes_at(
        &mut self,
        offset: u64,
        data: Bytes
    ) -> Self::WriteBytesAtFuture<'_>;
    fn set_len(&mut self, len: u64) -> Self::SetLenFuture<'_>;
    fn sync(&mut self) -> Self::SyncFuture<'_>;
}
Expand description

A trait to abstract async writing to different resources.

This trait does not require the notion of a current position, but instead requires explicitly passing the offset to write_at and write_bytes_at. In addition to the ability to write at an arbitrary offset, it also provides the ability to set the length of the resource.

This is similar to the io interface of sqlite. See xWrite in https://www.sqlite.org/c3ref/io_methods.html

Required Associated Types§

source

type WriteAtFuture<'a>: Future<Output = Result<(), Error>> + 'a where Self: 'a

The future returned by write_at

source

type WriteBytesAtFuture<'a>: Future<Output = Result<(), Error>> + 'a where Self: 'a

The future returned by write_bytes_at

source

type SetLenFuture<'a>: Future<Output = Result<(), Error>> + 'a where Self: 'a

The future returned by set_len

source

type SyncFuture<'a>: Future<Output = Result<(), Error>> + 'a where Self: 'a

The future returned by sync

Required Methods§

source

fn write_at(&mut self, offset: u64, data: &[u8]) -> Self::WriteAtFuture<'_>

Write the entire slice at the given position.

if self.len < offset + data.len(), the underlying resource will be extended. if self.len < offset, the gap will be filled with zeros.

source

fn write_bytes_at( &mut self, offset: u64, data: Bytes ) -> Self::WriteBytesAtFuture<'_>

Write the entire Bytes at the given position.

Use this if you have a Bytes, to avoid allocations. Other than that it is equivalent to AsyncSliceWriter::write_at.

source

fn set_len(&mut self, len: u64) -> Self::SetLenFuture<'_>

Set the length of the underlying storage.

source

fn sync(&mut self) -> Self::SyncFuture<'_>

Sync any buffers to the underlying storage.

Implementations on Foreign Types§

source§

impl<L, R> AsyncSliceWriter for Either<L, R>where L: AsyncSliceWriter + 'static, R: AsyncSliceWriter + 'static,

§

type WriteBytesAtFuture<'a> = Either<<L as AsyncSliceWriter>::WriteBytesAtFuture<'a>, <R as AsyncSliceWriter>::WriteBytesAtFuture<'a>>

source§

fn write_bytes_at( &mut self, offset: u64, data: Bytes ) -> <Either<L, R> as AsyncSliceWriter>::WriteBytesAtFuture<'_>

§

type WriteAtFuture<'a> = Either<<L as AsyncSliceWriter>::WriteAtFuture<'a>, <R as AsyncSliceWriter>::WriteAtFuture<'a>>

source§

fn write_at( &mut self, offset: u64, data: &[u8] ) -> <Either<L, R> as AsyncSliceWriter>::WriteAtFuture<'_>

§

type SyncFuture<'a> = Either<<L as AsyncSliceWriter>::SyncFuture<'a>, <R as AsyncSliceWriter>::SyncFuture<'a>>

source§

fn sync(&mut self) -> <Either<L, R> as AsyncSliceWriter>::SyncFuture<'_>

§

type SetLenFuture<'a> = Either<<L as AsyncSliceWriter>::SetLenFuture<'a>, <R as AsyncSliceWriter>::SetLenFuture<'a>>

source§

fn set_len( &mut self, len: u64 ) -> <Either<L, R> as AsyncSliceWriter>::SetLenFuture<'_>

source§

impl AsyncSliceWriter for BytesMut

§

type WriteBytesAtFuture<'a> = Ready<Result<(), Error>>

source§

fn write_bytes_at( &mut self, offset: u64, data: Bytes ) -> <BytesMut as AsyncSliceWriter>::WriteBytesAtFuture<'_>

§

type WriteAtFuture<'a> = Ready<Result<(), Error>>

source§

fn write_at( &mut self, offset: u64, data: &[u8] ) -> <BytesMut as AsyncSliceWriter>::WriteAtFuture<'_>

§

type SetLenFuture<'a> = Ready<Result<(), Error>>

source§

fn set_len( &mut self, len: u64 ) -> <BytesMut as AsyncSliceWriter>::SetLenFuture<'_>

§

type SyncFuture<'a> = Ready<Result<(), Error>>

source§

fn sync(&mut self) -> <BytesMut as AsyncSliceWriter>::SyncFuture<'_>

source§

impl<T> AsyncSliceWriter for Box<T, Global>where T: AsyncSliceWriter,

§

type WriteAtFuture<'a> = <T as AsyncSliceWriter>::WriteAtFuture<'a> where T: 'a

§

type WriteBytesAtFuture<'a> = <T as AsyncSliceWriter>::WriteBytesAtFuture<'a> where T: 'a

§

type SetLenFuture<'a> = <T as AsyncSliceWriter>::SetLenFuture<'a> where T: 'a

§

type SyncFuture<'a> = <T as AsyncSliceWriter>::SyncFuture<'a> where T: 'a

source§

fn write_at( &mut self, offset: u64, data: &[u8] ) -> <Box<T, Global> as AsyncSliceWriter>::WriteAtFuture<'_>

source§

fn write_bytes_at( &mut self, offset: u64, data: Bytes ) -> <Box<T, Global> as AsyncSliceWriter>::WriteBytesAtFuture<'_>

source§

fn set_len( &mut self, len: u64 ) -> <Box<T, Global> as AsyncSliceWriter>::SetLenFuture<'_>

source§

fn sync(&mut self) -> <Box<T, Global> as AsyncSliceWriter>::SyncFuture<'_>

source§

impl<'b, T> AsyncSliceWriter for &'b mut Twhere T: AsyncSliceWriter,

§

type WriteAtFuture<'a> = <T as AsyncSliceWriter>::WriteAtFuture<'a> where 'b: 'a, T: 'a

§

type WriteBytesAtFuture<'a> = <T as AsyncSliceWriter>::WriteBytesAtFuture<'a> where 'b: 'a, T: 'a

§

type SetLenFuture<'a> = <T as AsyncSliceWriter>::SetLenFuture<'a> where 'b: 'a, T: 'a

§

type SyncFuture<'a> = <T as AsyncSliceWriter>::SyncFuture<'a> where 'b: 'a, T: 'a

source§

fn write_at( &mut self, offset: u64, data: &[u8] ) -> <&'b mut T as AsyncSliceWriter>::WriteAtFuture<'_>

source§

fn write_bytes_at( &mut self, offset: u64, data: Bytes ) -> <&'b mut T as AsyncSliceWriter>::WriteBytesAtFuture<'_>

source§

fn set_len( &mut self, len: u64 ) -> <&'b mut T as AsyncSliceWriter>::SetLenFuture<'_>

source§

fn sync(&mut self) -> <&'b mut T as AsyncSliceWriter>::SyncFuture<'_>

Implementors§

source§

impl AsyncSliceWriter for File

source§

impl<W> AsyncSliceWriter for ConcatenateSliceWriter<W>where W: AsyncWrite + Unpin + 'static,

§

type WriteBytesAtFuture<'a> = Pin<Box<dyn Future<Output = Result<(), Error>> + 'a, Global>>

§

type WriteAtFuture<'a> = Pin<Box<dyn Future<Output = Result<(), Error>> + 'a, Global>>

§

type SyncFuture<'a> = Pin<Box<dyn Future<Output = Result<(), Error>> + 'a, Global>>

§

type SetLenFuture<'a> = Ready<Result<(), Error>>