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§
Sourcefn write_at(
&mut self,
offset: u64,
data: &[u8],
) -> impl Future<Output = Result<(), Error>>
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.
Sourcefn write_bytes_at(
&mut self,
offset: u64,
data: Bytes,
) -> impl Future<Output = Result<(), Error>>
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.
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.