Skip to main content

ResourceState

Enum ResourceState 

Source
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

Source

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

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

pub const fn is_terminal(&self) -> bool

Returns true if this state is terminal.

Source

pub const fn is_available(&self) -> bool

Returns true if the resource is available for allocation from a pool.

Source

pub const fn is_active(&self) -> bool

Returns true if the resource has an active owner.

Trait Implementations§

Source§

impl Clone for ResourceState

Source§

fn clone(&self) -> ResourceState

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 Copy for ResourceState

Source§

impl Debug for ResourceState

Source§

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

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

impl<'de> Deserialize<'de> for ResourceState

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for ResourceState

Source§

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

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

impl Eq for ResourceState

Source§

impl Hash for ResourceState

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for ResourceState

Source§

fn eq(&self, other: &ResourceState) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for ResourceState

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for ResourceState

Auto Trait Implementations§

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.