Crates.io | smallest-uint |
lib.rs | smallest-uint |
version | 0.1.5 |
source | src |
created_at | 2021-02-06 08:46:32.670046 |
updated_at | 2022-12-26 04:37:47.761453 |
description | Gets the smallest unsigned integer type that can represent a given value |
homepage | |
repository | https://github.com/taylordotfish/smallest-uint |
max_upload_size | |
id | 351465 |
size | 23,280 |
Given an unsigned type-level integer, provides access to
the smallest primitive unsigned integer type (u8
, u16
, etc.) that
can represent the integer’s value (or all values less than that value).
This is mainly useful for minimizing memory usage when building data structures.
This crate depends only on core
, so it can be used in no_std
environments.
use smallest_uint::{SmallestUIntFor, SmallestUIntUpTo};
use std::any::TypeId;
use typenum::U65536;
assert_eq!(TypeId::of::<SmallestUIntUpTo<U65536>>(), TypeId::of::<u16>());
assert_eq!(TypeId::of::<SmallestUIntFor<U65536>>(), TypeId::of::<u32>());
If the feature u128
is enabled, this crate will use the u128
type.
This feature is enabled by default.