tstr

Trait 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

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

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

Source§

const U128: u128 = T::U128