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§
Sourcefn commit(&self, final_len: Option<u64>) -> StorageResult<()>
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).
Sourcefn path(&self) -> Option<&Path>
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.
Sourcefn reactivate(&self) -> StorageResult<()>
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.
Sourcefn read_at(&self, offset: u64, buf: &mut [u8]) -> StorageResult<usize>
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.
Sourcefn status(&self) -> ResourceStatus
fn status(&self) -> ResourceStatus
Get resource status.
Sourcefn wait_range(&self, range: Range<u64>) -> StorageResult<WaitOutcome>
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.
Provided Methods§
Sourcefn contains_range(&self, _range: Range<u64>) -> bool
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.
Sourcefn next_gap(&self, _from: u64, _limit: u64) -> Option<Range<u64>>
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.
Sourcefn read_into(&self, buf: &mut Vec<u8>) -> StorageResult<usize>
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.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".