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
40
41
42
43
44
45
46
47
48
49
50
//! Traits for converting type-level-value to a value.

///////////////////////////////////////////////////////////////////////////////

/// Converts this type-level value to a usize.
pub trait ToUsize {
    /// The `usize` that this type represents
    const USIZE: usize;
}

///////////////////////////////////////////////////////////////////////////////

mod sealed {
    pub trait Sealed {}
}

use self::sealed::Sealed;

/// Converts this type-level digit to a u8.
#[doc(hidden)]
pub trait ToDigit: Sealed {
    /// The digit that this type represents
    const DIGIT: u8;
}

#[cfg(any(not(feature = "use_const_str"), feature = "disable_const_str"))]
macro_rules! impl_to_digit {
    ( $($self:ty=$value:literal,)* ) => (
        $(
            impl Sealed for $self {}
            impl ToDigit for $self {
                const DIGIT:u8=$value;
            }
        )*
    )
}

#[cfg(any(not(feature = "use_const_str"), feature = "disable_const_str"))]
impl_to_digit! {
    crate::__0=0,
    crate::__1=1,
    crate::__2=2,
    crate::__3=3,
    crate::__4=4,
    crate::__5=5,
    crate::__6=6,
    crate::__7=7,
    crate::__8=8,
    crate::__9=9,
}