pub struct Batch<'a> { /* private fields */ }Expand description
A scoped lifetime that protects blobs from garbage collection.
All temporary tags created through a Batch are kept alive until the batch
is dropped, at which point they are released atomically and the protected
blobs become eligible for GC again.
A typical use case is protecting a blob during a long-running write (or download) where GC could otherwise collect the partially-written data.
§Example
use iroh_blobs::{store::mem::MemStore, Hash};
let store = MemStore::new();
// Hash is known upfront (e.g. from a download ticket).
let hash = Hash::new(b"example content");
let batch = store.blobs().batch().await?;
let _guard = batch.temp_tag(hash).await?;
// GC will not collect `hash` for as long as `_guard` and `batch` are alive.
// ... perform long-running write or network download here ...
drop(_guard);
// Any un-upgraded blobs from the batch are now eligible for garbage collectionImplementations§
Source§impl<'a> Batch<'a>
impl<'a> Batch<'a>
pub fn add_bytes(&self, data: impl Into<Bytes>) -> BatchAddProgress<'_>
pub fn add_bytes_with_opts( &self, options: impl Into<AddBytesOptions>, ) -> BatchAddProgress<'_>
pub fn add_slice(&self, data: impl AsRef<[u8]>) -> BatchAddProgress<'_>
pub fn add_path_with_opts( &self, options: impl Into<AddPathOptions>, ) -> BatchAddProgress<'_>
Sourcepub async fn temp_tag(&self, value: impl Into<HashAndFormat>) -> Result<TempTag>
pub async fn temp_tag(&self, value: impl Into<HashAndFormat>) -> Result<TempTag>
Pins a hash inside this batch scope, protecting it from garbage collection.
The returned TempTag keeps the blob alive until either the tag or
the batch is dropped. This is the recommended way to protect a blob
during a long-running write or download where GC might otherwise collect
the partially-written data.
Auto Trait Implementations§
impl<'a> Freeze for Batch<'a>
impl<'a> !RefUnwindSafe for Batch<'a>
impl<'a> Send for Batch<'a>
impl<'a> Sync for Batch<'a>
impl<'a> Unpin for Batch<'a>
impl<'a> UnsafeUnpin for Batch<'a>
impl<'a> !UnwindSafe for Batch<'a>
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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