Skip to main content

ResourceExt

Trait ResourceExt 

Source
pub trait ResourceExt:
    Send
    + Sync
    + 'static {
Show 14 methods // Required methods fn commit(&self, final_len: Option<u64>) -> StorageResult<()>; fn fail(&self, reason: String); fn len(&self) -> Option<u64>; fn path(&self) -> Option<&Path>; fn reactivate(&self) -> StorageResult<()>; fn read_at(&self, offset: u64, buf: &mut [u8]) -> StorageResult<usize>; fn status(&self) -> ResourceStatus; fn wait_range(&self, range: Range<u64>) -> StorageResult<WaitOutcome>; fn write_at(&self, offset: u64, data: &[u8]) -> StorageResult<()>; // Provided methods fn contains_range(&self, _range: Range<u64>) -> bool { ... } fn is_empty(&self) -> bool { ... } fn next_gap(&self, _from: u64, _limit: u64) -> Option<Range<u64>> { ... } fn read_into(&self, buf: &mut Vec<u8>) -> StorageResult<usize> { ... } fn write_all(&self, data: &[u8]) -> StorageResult<()> { ... }
}
Expand description

Unified sync resource trait.

Covers both incremental streaming (segments, progressive downloads) and atomic whole-file (playlists, keys, indexes) use-cases.

For streaming: use write_at + commit. For atomic: use write_all / read_into convenience methods.

Required Methods§

Source

fn commit(&self, final_len: Option<u64>) -> StorageResult<()>

Mark the resource as fully written.

If final_len is provided, the backing storage may be truncated to that size.

§Errors

Returns error if the resource is cancelled, failed, or the backend cannot finalize (e.g. file truncation or reopen fails).

Source

fn fail(&self, reason: String)

Mark the resource as failed.

Source

fn len(&self) -> Option<u64>

Get the committed length, if known.

Source

fn path(&self) -> Option<&Path>

Get the file path, if backed by a file.

Returns None for in-memory resources that have no filesystem path.

Source

fn reactivate(&self) -> StorageResult<()>

Reactivate a committed resource for continued writing.

Transitions Committed -> Active: reopens the backing store for writing, resets committed flag, and clears final_len. Existing data remains available for reading. New data can be written at any offset.

Use for resuming partial downloads where the resource is smaller than the expected total.

No-op if the resource is already Active.

§Errors

Returns error if the resource is cancelled, failed, or the backend cannot reopen for writing.

Source

fn read_at(&self, offset: u64, buf: &mut [u8]) -> StorageResult<usize>

Read data at the given offset into buf.

Returns the number of bytes read.

§Errors

Returns error if the resource is cancelled, failed, or the read fails.

Source

fn status(&self) -> ResourceStatus

Get resource status.

Source

fn wait_range(&self, range: Range<u64>) -> StorageResult<WaitOutcome>

Wait until the given byte range is available.

Blocks the calling thread using Condvar until data is written or the resource reaches EOF / error / cancellation.

§Errors

Returns error if the range is invalid, the resource is cancelled, or the resource has failed.

Source

fn write_at(&self, offset: u64, data: &[u8]) -> StorageResult<()>

Write data at the given offset.

§Errors

Returns error if the resource is cancelled, failed, committed (and the backend does not support post-commit writes), or the write fails.

Provided Methods§

Source

fn contains_range(&self, _range: Range<u64>) -> bool

Check if the given byte range is fully covered by available data (non-blocking).

Returns false by default. Override for implementations that track available byte ranges.

Source

fn is_empty(&self) -> bool

Returns true if the resource has been committed with zero length.

Source

fn next_gap(&self, _from: u64, _limit: u64) -> Option<Range<u64>>

Find the first gap in available data starting from from, up to limit.

Returns None by default (conservative: assumes no data available). Override for implementations that track available byte ranges.

Source

fn read_into(&self, buf: &mut Vec<u8>) -> StorageResult<usize>

Read the entire resource contents into a caller-provided buffer.

The buffer is resized to fit the data. Returns the number of bytes read. Returns 0 if resource has no data.

§Errors

Returns error if the resource is cancelled, failed, or the read fails.

Source

fn write_all(&self, data: &[u8]) -> StorageResult<()>

Write entire contents and commit atomically.

§Errors

Returns error if the write or commit fails.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§