o3/buffer/resident/
bound.rs1use std::marker;
2
3#[derive(Clone, Copy, PartialEq, Eq)]
5pub enum Limit {
6 AtMost(usize),
7 Unbounded,
8}
9
10pub trait Bound {
12 const LIMIT: Limit;
13}
14
15pub enum AtMost<const N: usize> {}
17
18impl<const N: usize> Bound for AtMost<N> {
19 const LIMIT: Limit = Limit::AtMost(N);
20}
21
22pub enum Unbounded {}
24
25impl Bound for Unbounded {
26 const LIMIT: Limit = Limit::Unbounded;
27}
28
29pub 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}