dope_core/driver/route/table/connection/
capacity.rs1use o3::collections::slab;
2
3use crate::driver::route::{self, table};
4
5#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)]
7#[repr(transparent)]
8pub struct ConnectionCapacity(route::SlotIndex);
9
10impl ConnectionCapacity {
11 pub const fn new(value: usize) -> Option<Self> {
12 match table::Capacity::new(value) {
13 Some(capacity) if capacity.get() != 0 => {
14 match route::SlotIndex::try_new(capacity.raw()) {
15 Some(sentinel) => Some(Self(sentinel)),
16 None => None,
17 }
18 }
19 Some(_) | None => None,
20 }
21 }
22
23 pub const fn get(self) -> usize {
24 self.0.raw() as usize
25 }
26
27 pub const fn raw(self) -> u32 {
28 self.0.raw()
29 }
30
31 pub const fn table(self) -> table::Capacity {
32 table::Capacity(slab::Capacity::new(self.0.raw()))
33 }
34
35 pub const fn sentinel(self) -> route::SlotIndex {
36 self.0
37 }
38}