Trait tstr::ToUint

source ·
pub trait ToUint: Sized {
    const U128: u128;
    const USIZE: usize = _;

    // Provided methods
    fn to_usize(&self) -> usize { ... }
    fn to_u128(&self) -> u128 { ... }
}
Expand description

Converts a TStr to unsigned integers.

§Example

use tstr::{ToUint, TS, ts};

type Zero = TS!(0);
type N8   = TS!(8);
type N13  = TS!(13);
type N15  = TS!(0xF);
type N16  = TS!(0b10000);

assert_eq!(Zero::USIZE, 0);
assert_eq!(N8::USIZE, 8);
assert_eq!(N13::USIZE, 13);
assert_eq!(N15::USIZE, 15);
assert_eq!(N16::USIZE, 16);

assert_eq!(ts!(0).to_u128(), 0);
assert_eq!(ts!(8).to_u128(), 8);
assert_eq!(ts!(13).to_u128(), 13);
assert_eq!(ts!(0xF).to_u128(), 15);
assert_eq!(ts!(0b10000).to_u128(), 16);

Required Associated Constants§

source

const U128: u128

The u128 value of the type.

Provided Associated Constants§

source

const USIZE: usize = _

The usize value of the type.

By default this value is a saturated cast from Self::U128.

Provided Methods§

source

fn to_usize(&self) -> usize

Gets the usize value of this type

By default this value is a saturated cast from Self::U128.

source

fn to_u128(&self) -> u128

Gets the u128 value of this type

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<T> ToUint for TStr<T>
where T: ToUint,

source§

const U128: u128 = T::U128