pub struct Write<B: Blob> { /* private fields */ }
Expand description
A writer that buffers content to a Blob to optimize the performance of appending or updating data.
§Example
use commonware_runtime::{Runner, buffer::{Write, Read}, Blob, Error, Storage, deterministic};
let executor = deterministic::Runner::default();
executor.start(|context| async move {
// Open a blob for writing
let (blob, size) = context.open("my_partition", b"my_data").await.expect("unable to open blob");
assert_eq!(size, 0);
// Create a buffered writer with 16-byte buffer
let mut blob = Write::new(blob, 0, 16);
blob.write_at(b"hello".to_vec(), 0).await.expect("write failed");
blob.sync().await.expect("sync failed");
// Write more data in multiple flushes
blob.write_at(b" world".to_vec(), 5).await.expect("write failed");
blob.write_at(b"!".to_vec(), 11).await.expect("write failed");
blob.sync().await.expect("sync failed");
// Read back the data to verify
let (blob, size) = context.open("my_partition", b"my_data").await.expect("unable to reopen blob");
let mut reader = Read::new(blob, size, 8);
let mut buf = vec![0u8; size as usize];
reader.read_exact(&mut buf, size as usize).await.expect("read failed");
assert_eq!(&buf, b"hello world!");
});
Implementations§
Trait Implementations§
Source§impl<B: Blob> Blob for Write<B>
impl<B: Blob> Blob for Write<B>
Source§async fn read_at(
&self,
buf: impl Into<StableBuf> + Send,
offset: u64,
) -> Result<StableBuf, Error>
async fn read_at( &self, buf: impl Into<StableBuf> + Send, offset: u64, ) -> Result<StableBuf, Error>
Read from the blob at the given offset. Read more
Source§async fn write_at(
&self,
buf: impl Into<StableBuf> + Send,
offset: u64,
) -> Result<(), Error>
async fn write_at( &self, buf: impl Into<StableBuf> + Send, offset: u64, ) -> Result<(), Error>
Write
buf
to the blob at the given offset.Auto Trait Implementations§
impl<B> Freeze for Write<B>
impl<B> !RefUnwindSafe for Write<B>
impl<B> Send for Write<B>
impl<B> Sync for Write<B>
impl<B> Unpin for Write<B>
impl<B> !UnwindSafe for Write<B>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more