| Crates.io | autosized-num |
| lib.rs | autosized-num |
| version | 0.1.0 |
| created_at | 2025-10-07 05:54:24.453899+00 |
| updated_at | 2025-10-07 05:54:24.453899+00 |
| description | Auto-sized integer macros: choose the smallest signed/unsigned type for a literal at compile time. |
| homepage | |
| repository | https://github.com/yua134/autosized_num |
| max_upload_size | |
| id | 1871245 |
| size | 33,507 |
Auto-sized integer macros: choose the smallest signed/unsigned type for a literal at compile time.
Auto-sized integer macros
Automatically choose the smallest fitting integer type for a literal.
Unsigned support
auto_sized_unsigned! / auto_sized_unsigned_val! → expands to u8, u16, u32, u64, or u128.
Signed support
auto_sized_signed! / auto_sized_signed_val! → expands to i8, i16, i32, i64, or i128.
Unified macros
auto_sized_int! / auto_sized_int_val! → automatically pick signed or unsigned depending on the literal.
Accepts the full i128 range.
Type and value variants
*_unsigned!, *_signed!, *_int! → return a type.*_val variants → return a value with an explicit cast.no_std friendly
Expanded code uses only primitive integer types, so it works in no_std environments.
Add the crate with Cargo:
cargo add autosized-num
Then import the macros and use them in your code:
use autosized::*;
fn main() {
// Type macros
type T1 = auto_sized_unsigned!(300); // expands to u16
type T2 = auto_sized_signed!(-200); // expands to i16
type T3 = auto_sized_int!(10); // expands to u8
type T4 = auto_sized_int!(-10); // expands to i8
// Value macros
let a = auto_sized_unsigned_val!(300); // 300u16
let b = auto_sized_signed_val!(-200); // -200i16
let c = auto_sized_int_val!(10); // 10u8
let d = auto_sized_int_val!(-10); // -10i8
println!("{a}, {b}, {c}, {d}");
}
auto_sized_int! / auto_sized_int_val! accept the full i128 range.no_std environments.