pub trait ArrayLen: 'static + Copy + Sealed {
    fn as_usize(self) -> usize;
fn from_usize(x: usize) -> Option<Self>; }
Expand description

Integer types that are valid lengths for Array<T>.

Valid options are: u8, u16, u32, u64, usize, and nothing else.


use varlen::prelude::*;
assert_eq!(Some(4u8), u8::from_usize(4usize));

Required methods

Converts to a usize via an as (truncating) conversion.

use varlen::prelude::*;
assert_eq!(4usize, 4u8.as_usize());
assert_eq!(u64::MAX as usize, u64::MAX.as_usize());

Converts from a usize, returning None if it doesn’t fit in the destination.

use varlen::prelude::*;
assert_eq!(Some(4u8), ArrayLen::from_usize(4));
assert_eq!(None, u8::from_usize(257));

Implementations on Foreign Types