Crates.io | num-bytes |
lib.rs | num-bytes |
version | 0.4.0 |
source | src |
created_at | 2021-08-06 14:52:22.775549 |
updated_at | 2021-08-22 04:48:31.321706 |
description | Traits for converting primitives into bytes. |
homepage | |
repository | https://github.com/JonathanWoollett-Light/num-bytes |
max_upload_size | |
id | 432478 |
size | 5,443 |
Traits for converting primitives into bytes.
Kinda like a bad extension to num.
Usage is a little tricky:
let a = [8,0];
let b: i16 = from_generic(a);
assert_eq!(b,8);
fn from_generic<T: num_bytes::FromBytes<N>, const N: usize>(x: [u8;N]) -> T {
T::from_le_bytes(x)
}
and:
let a = 8i16;
let b = into_generic(a);
assert_eq!(b,[8,0]);
fn into_generic<T: num_bytes::IntoBytes<N>, const N: usize>(x: T) -> [u8;N] {
x.into_le_bytes()
}