Skip to main content

nanvm_lib/common/
uint.rs

1use core::ops::{AddAssign, Sub};
2
3/// An unsigned index type: `u32`, the index of every VM container, and
4/// `usize`, a slice's.
5pub trait Uint:
6    Sized + Copy + Default + PartialEq + AddAssign + Sub<Output = Self> + From<u8>
7{
8    /// The index as a `usize`, the type of an iterator's `size_hint`.
9    fn to_usize(self) -> usize;
10}
11
12impl Uint for u32 {
13    fn to_usize(self) -> usize {
14        self as usize
15    }
16}
17
18impl Uint for usize {
19    fn to_usize(self) -> usize {
20        self
21    }
22}