Skip to main content

o3/buffer/resident/
bound.rs

1use std::marker;
2
3/// Maximum resident backing retained by one owner.
4#[derive(Clone, Copy, PartialEq, Eq)]
5pub enum Limit {
6    AtMost(usize),
7    Unbounded,
8}
9
10/// Type-level resident backing bound.
11pub trait Bound {
12    const LIMIT: Limit;
13}
14
15/// Proof of a finite resident backing bound.
16pub enum AtMost<const N: usize> {}
17
18impl<const N: usize> Bound for AtMost<N> {
19    const LIMIT: Limit = Limit::AtMost(N);
20}
21
22/// Proof that resident backing has no finite static bound.
23pub enum Unbounded {}
24
25impl Bound for Unbounded {
26    const LIMIT: Limit = Limit::Unbounded;
27}
28
29/// Bound covering either of two retained owner shapes.
30pub struct Max<L, R>(marker::PhantomData<fn() -> (L, R)>);
31
32impl<L: Bound, R: Bound> Bound for Max<L, R> {
33    const LIMIT: Limit = match (L::LIMIT, R::LIMIT) {
34        (Limit::AtMost(left), Limit::AtMost(right)) => {
35            Limit::AtMost(if left > right { left } else { right })
36        }
37        (Limit::Unbounded, _) | (_, Limit::Unbounded) => Limit::Unbounded,
38    };
39}