Trait bao_tree::io::fsm::AsyncSliceWriter
source · 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§
sourcetype WriteAtFuture<'a>: Future<Output = Result<(), Error>> + 'a
where
Self: 'a
type WriteAtFuture<'a>: Future<Output = Result<(), Error>> + 'a where Self: 'a
The future returned by write_at
sourcetype WriteBytesAtFuture<'a>: Future<Output = Result<(), Error>> + 'a
where
Self: 'a
type WriteBytesAtFuture<'a>: Future<Output = Result<(), Error>> + 'a where Self: 'a
The future returned by write_bytes_at
Required Methods§
sourcefn write_at(&mut self, offset: u64, data: &[u8]) -> Self::WriteAtFuture<'_>
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.
sourcefn write_bytes_at(
&mut self,
offset: u64,
data: Bytes
) -> Self::WriteBytesAtFuture<'_>
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.
sourcefn set_len(&mut self, len: u64) -> Self::SetLenFuture<'_>
fn set_len(&mut self, len: u64) -> Self::SetLenFuture<'_>
Set the length of the underlying storage.
sourcefn sync(&mut self) -> Self::SyncFuture<'_>
fn sync(&mut self) -> Self::SyncFuture<'_>
Sync any buffers to the underlying storage.