sel4_async_time/
sub_key.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//
// Copyright 2023, Colias Group, LLC
//
// SPDX-License-Identifier: BSD-2-Clause
//

pub trait SubKey: Sized + Ord {
    fn min() -> Self;

    #[allow(dead_code)]
    fn max() -> Self;

    fn succ(&self) -> Option<Self>;
}

macro_rules! sub_key_impl {
    ($t:ty) => {
        impl SubKey for $t {
            fn min() -> Self {
                <$t>::MIN
            }

            fn max() -> Self {
                <$t>::MAX
            }

            fn succ(&self) -> Option<Self> {
                self.checked_add(1)
            }
        }
    };
}

sub_key_impl!(u8);
sub_key_impl!(u16);
sub_key_impl!(u32);
sub_key_impl!(u64);
sub_key_impl!(u128);
sub_key_impl!(usize);