num-bytes

Crates.ionum-bytes
lib.rsnum-bytes
version0.4.0
sourcesrc
created_at2021-08-06 14:52:22.775549
updated_at2021-08-22 04:48:31.321706
descriptionTraits for converting primitives into bytes.
homepage
repositoryhttps://github.com/JonathanWoollett-Light/num-bytes
max_upload_size
id432478
size5,443
Jonathan Woollett-Light (JonathanWoollett-Light)

documentation

https://docs.rs/num-bytes/

README

num-bytes

Crates.io lib.rs.io docs

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()
}
Commit count: 13

cargo fmt