pipecircuit 0.0.18

Correct. Robust. Fast. Portable. Pick four.
Documentation
mod creation;
#[cfg(feature = "performance-evidence")]
mod evidence;
mod lease;
mod pool;
mod reservation;

use alloc::{boxed::Box, vec::Vec};
use core::{cell::Cell, ops::Range};

pub use creation::BytePoolCreationError;
#[cfg(feature = "performance-evidence")]
pub use evidence::BytePoolEvidence;
pub use lease::{ByteLease, RetainedByteLease};
pub use pool::{
    BytePoolInconsistency, BytePoolLeaseOutcome, BytePoolRecycleOutcome, BytePoolResumeOutcome,
    BytePoolStatistics,
};
pub use reservation::{ByteLeaseReservation, BytePoolMaterializeOutcome, BytePoolReserveOutcome};

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
enum LeaseStatus {
    Vacant,
    Leased,
    Released,
    Exhausted,
}

struct LeaseRecord {
    identity: Cell<Box<[u8]>>,
    identity_address: usize,
    generation: u64,
    range: Range<usize>,
    status: Cell<LeaseStatus>,
    next: Cell<Option<usize>>,
}

pub struct BytePool {
    storage: Box<[u8]>,
    leases: Box<[LeaseRecord]>,
    free_extents: Vec<Range<usize>>,
    available_lease_head: Option<usize>,
    released_lease_head: Cell<Option<usize>>,
    exhausted_lease_count: usize,
    #[cfg(feature = "performance-evidence")]
    evidence: BytePoolEvidence,
}

#[cfg(test)]
mod tests;