pub enum ResourceState {
Pooled,
Owned,
Borrowed,
Leased,
Transit,
Freed,
}Expand description
Resource ownership state machine.
Per Doc 03, Section 3.1-3.2: tracks the lifecycle of host-managed resources
(primarily buffers). Extended here with Transit and Freed states.
State transition diagram:
Pooled -> Owned -> Borrowed -> Owned (borrow released)
-> Leased -> Owned (lease expired)
-> Transit -> Owned (new owner)
-> Pooled (released)
Any -> Freed (forced cleanup or shutdown)§Examples
use torvyn_types::ResourceState;
let state = ResourceState::Pooled;
assert!(state.can_transition_to(&ResourceState::Owned));
assert!(!state.can_transition_to(&ResourceState::Borrowed));Variants§
Pooled
The resource is in a buffer pool, not in active use.
Owned
The resource is exclusively owned by one entity.
Borrowed
The resource is owned but has outstanding read-only borrows.
Leased
The resource is held under a time- or scope-bounded lease.
Transit
The resource is in transit between owners (host holds temporarily).
Freed
The resource has been freed and its slot may be reused.
Implementations§
Source§impl ResourceState
impl ResourceState
Sourcepub fn can_transition_to(&self, target: &ResourceState) -> bool
pub fn can_transition_to(&self, target: &ResourceState) -> bool
Returns true if transitioning from self to target is legal.
Legal transitions (per Doc 03, Section 3.2, extended):
- Pooled -> Owned (allocate)
- Owned -> Borrowed (borrow started)
- Owned -> Leased (lease granted)
- Owned -> Transit (transfer initiated)
- Owned -> Pooled (released to pool)
- Owned -> Freed (deallocated)
- Borrowed -> Owned (all borrows released)
- Borrowed -> Borrowed (additional borrow — same state)
- Leased -> Owned (lease expired/released)
- Transit -> Owned (transfer completed to new owner)
- Any -> Freed (forced cleanup: crash, shutdown)
§HOT PATH — called per resource state change.
Sourcepub fn transition_to(
self,
target: ResourceState,
) -> Result<ResourceState, InvalidTransition>
pub fn transition_to( self, target: ResourceState, ) -> Result<ResourceState, InvalidTransition>
Attempt to transition from self to target.
Returns Ok(target) if the transition is legal, or
Err(InvalidTransition) if it is not.
§HOT PATH — called per resource state change.
Sourcepub const fn is_terminal(&self) -> bool
pub const fn is_terminal(&self) -> bool
Returns true if this state is terminal.
Sourcepub const fn is_available(&self) -> bool
pub const fn is_available(&self) -> bool
Returns true if the resource is available for allocation from a pool.
Trait Implementations§
Source§impl Clone for ResourceState
impl Clone for ResourceState
Source§fn clone(&self) -> ResourceState
fn clone(&self) -> ResourceState
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more