sel4/
const_helpers.rs
1#![allow(clippy::assertions_on_constants)]
8
9use sel4_config::sel4_cfg_attr;
10
11use crate::Word;
12
13const _: () = assert!(Word::BITS == usize::BITS);
14const _: () = assert!(u32::BITS <= usize::BITS);
15
16pub(crate) const fn word_into_usize(x: Word) -> usize {
17 x as usize
18}
19
20pub(crate) const fn usize_into_word(x: usize) -> Word {
21 x as Word
22}
23
24pub(crate) const fn u32_into_usize(x: u32) -> usize {
25 x as usize
26}
27
28#[allow(dead_code)]
29pub(crate) const fn u32_into_word(x: u32) -> Word {
30 x as Word
31}
32
33#[sel4_cfg_attr(not(KERNEL_MCS), allow(dead_code))]
34pub(crate) const fn usize_max(x: usize, y: usize) -> usize {
35 if x >= y {
36 x
37 } else {
38 y
39 }
40}