Skip to main content

Resource

Struct Resource 

Source
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:

Implementations§

Source§

impl<D: Driver> Resource<D>

Source

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).

Source

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.

Source§

impl Resource<MemDriver>

Source

pub fn new(cancel: CancellationToken) -> Self

Create a new empty in-memory resource.

§Panics

Panics if MemDriver::open fails (should never happen with default options).

Trait Implementations§

Source§

impl<D: DriverIo> Clone for Resource<D>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<D: DriverIo + Debug> Debug for Resource<D>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<Resource<MemDriver>> for StorageResource

Source§

fn from(r: MemResource) -> Self

Converts to this type from the input type.
Source§

impl From<Resource<MmapDriver>> for StorageResource

Available on non-WebAssembly only.
Source§

fn from(r: MmapResource) -> Self

Converts to this type from the input type.
Source§

impl<D: DriverIo> ResourceExt for Resource<D>

Source§

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

Mark the resource as fully written. Read more
Source§

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

Check if the given byte range is fully covered by available data (non-blocking). Read more
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 next_gap(&self, from: u64, limit: u64) -> Option<Range<u64>>

Find the first gap in available data starting from from, up to limit. Read more
Source§

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

Get the file path, if backed by a file. Read more
Source§

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

Reactivate a committed resource for continued writing. Read more
Source§

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

Read data at the given offset into buf. Read more
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. Read more
Source§

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

Write data at the given offset. Read more
Source§

fn is_empty(&self) -> bool

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

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

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

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

Write entire contents and commit atomically. Read more

Auto Trait Implementations§

§

impl<D> Freeze for Resource<D>

§

impl<D> !RefUnwindSafe for Resource<D>

§

impl<D> Send for Resource<D>

§

impl<D> Sync for Resource<D>

§

impl<D> Unpin for Resource<D>

§

impl<D> UnsafeUnpin for Resource<D>

§

impl<D> !UnwindSafe for Resource<D>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> MaybeSend for T
where T: Send,

Source§

impl<T> MaybeSync for T
where T: Sync,