Trait AsyncSliceWriter

Source
pub trait AsyncSliceWriter: Sized {
    // Required methods
    fn write_at(
        &mut self,
        offset: u64,
        data: &[u8],
    ) -> impl Future<Output = Result<(), Error>>;
    fn write_bytes_at(
        &mut self,
        offset: u64,
        data: Bytes,
    ) -> impl Future<Output = Result<(), Error>>;
    fn set_len(&mut self, len: u64) -> impl Future<Output = Result<(), Error>>;
    fn sync(&mut self) -> impl Future<Output = Result<(), Error>>;
}
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 Methods§

Source

fn write_at( &mut self, offset: u64, data: &[u8], ) -> impl Future<Output = Result<(), Error>>

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, ) -> impl Future<Output = Result<(), Error>>

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) -> impl Future<Output = Result<(), Error>>

Set the length of the underlying storage.

Source

fn sync(&mut self) -> impl Future<Output = Result<(), Error>>

Sync any buffers to the underlying storage.

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 AsyncSliceWriter for Vec<u8>

Source§

async fn write_bytes_at( &mut self, offset: u64, data: Bytes, ) -> Result<(), Error>

Source§

async fn write_at(&mut self, offset: u64, data: &[u8]) -> Result<(), Error>

Source§

async fn set_len(&mut self, len: u64) -> Result<(), Error>

Source§

async fn sync(&mut self) -> Result<(), Error>

Source§

impl AsyncSliceWriter for BytesMut

Source§

async fn write_bytes_at( &mut self, offset: u64, data: Bytes, ) -> Result<(), Error>

Source§

async fn write_at(&mut self, offset: u64, data: &[u8]) -> Result<(), Error>

Source§

async fn set_len(&mut self, len: u64) -> Result<(), Error>

Source§

async fn sync(&mut self) -> Result<(), Error>

Source§

impl<T> AsyncSliceWriter for &mut T

Source§

async fn write_at(&mut self, offset: u64, data: &[u8]) -> Result<(), Error>

Source§

async fn write_bytes_at( &mut self, offset: u64, data: Bytes, ) -> Result<(), Error>

Source§

async fn set_len(&mut self, len: u64) -> Result<(), Error>

Source§

async fn sync(&mut self) -> Result<(), Error>

Source§

impl<T> AsyncSliceWriter for Box<T>

Source§

async fn write_at(&mut self, offset: u64, data: &[u8]) -> Result<(), Error>

Source§

async fn write_bytes_at( &mut self, offset: u64, data: Bytes, ) -> Result<(), Error>

Source§

async fn set_len(&mut self, len: u64) -> Result<(), Error>

Source§

async fn sync(&mut self) -> Result<(), Error>

Implementors§