Expand description
Conditional aliases to numeric types.
§Examples
use std::fs::File;
use condtype::num::Usize64;
fn handle_throughput(bytes: Usize64) {
// ...
}
// usize
let s: &str = // ...
handle_throughput(s.len() as Usize64);
// u64
let f: File = // ...
handle_throughput(f.metadata()?.len() as Usize64);§Pitfalls
Because these are type aliases, some operations may happen to work for the current target but not for other targets.
The following example handles Usize32 explicitly as usize or u32
depending on whether the platform is 64-bit or 32-bit:
#[cfg(target_pointer_width = "64")]
let x: Usize32 = usize::MAX;
#[cfg(target_pointer_width = "32")]
let x: Usize32 = u32::MAX;Instead, the code should be made portable by using an as cast:
let x: Usize32 = usize::MAX as Usize32;Type Aliases§
- Isize16
- A signed integer that is convertible from
isizeandi8–i16. - Isize32
- A signed integer that is convertible from
isizeandi8–i32. - Isize64
- A signed integer that is convertible from
isizeandi8–i64. - Isize128
- A signed integer that is convertible from
isizeandi8–i128. - Usize16
- An unsigned integer that is convertible from
usizeandu8–u16. - Usize32
- An unsigned integer that is convertible from
usizeandu8–u32. - Usize64
- An unsigned integer that is convertible from
usizeandu8–u64. - Usize128
- An unsigned integer that is convertible from
usizeandu8–u128.