pub struct Resource<D: DriverIo> { /* private fields */ }Expand description
Generic storage resource parameterized by backend driver.
Owns the common state machine (range tracking, committed/failed flags,
condvar wait coordination, cancellation) and delegates backend-specific
I/O to D.
Use via type aliases:
MmapResource=Resource<MmapDriver>MemResource=Resource<MemDriver>
Implementations§
Source§impl<D: Driver> Resource<D>
impl<D: Driver> Resource<D>
Sourcepub fn open(cancel: CancellationToken, opts: D::Options) -> StorageResult<Self>
pub fn open(cancel: CancellationToken, opts: D::Options) -> StorageResult<Self>
Open a resource from driver options with no availability observer.
D is resolved at the call site by the type of opts (e.g.
Resource::open(token, MmapOptions { .. }) resolves to
Resource<MmapDriver>::open). The crate-private Driver trait
drives the binding without exposing its Options associated type
as a second canonical path to the public MemOptions / MmapOptions.
§Errors
Returns error if D::open(opts) fails (e.g. file I/O failure).
Sourcepub fn open_with_observer(
cancel: CancellationToken,
opts: D::Options,
observer: Option<Arc<dyn AvailabilityObserver>>,
) -> StorageResult<Self>
pub fn open_with_observer( cancel: CancellationToken, opts: D::Options, observer: Option<Arc<dyn AvailabilityObserver>>, ) -> StorageResult<Self>
Open a resource with an optional AvailabilityObserver. The
observer (if any) fires after every successful write_at and
after a successful commit that supplies a final length. Hooks
run after the state lock is released.
§Errors
Returns error if D::open(opts) fails.
Trait Implementations§
Source§impl From<Resource<MemDriver>> for StorageResource
impl From<Resource<MemDriver>> for StorageResource
Source§fn from(r: MemResource) -> Self
fn from(r: MemResource) -> Self
Source§impl From<Resource<MmapDriver>> for StorageResource
Available on non-WebAssembly only.
impl From<Resource<MmapDriver>> for StorageResource
Source§fn from(r: MmapResource) -> Self
fn from(r: MmapResource) -> Self
Source§impl<D: DriverIo> ResourceExt for Resource<D>
impl<D: DriverIo> ResourceExt for Resource<D>
Source§fn commit(&self, final_len: Option<u64>) -> StorageResult<()>
fn commit(&self, final_len: Option<u64>) -> StorageResult<()>
Source§fn contains_range(&self, range: Range<u64>) -> bool
fn contains_range(&self, range: Range<u64>) -> bool
Source§fn reactivate(&self) -> StorageResult<()>
fn reactivate(&self) -> StorageResult<()>
Source§fn read_at(&self, offset: u64, buf: &mut [u8]) -> StorageResult<usize>
fn read_at(&self, offset: u64, buf: &mut [u8]) -> StorageResult<usize>
buf. Read more