lazy-bytes-cast

Build status Build Status Crates.io Docs.rs

This crate provides simple methods to cast from and into byte arrays.

Note

The crates will not take care of byte order for you. Cuz lazy.

Usage

Slice integer as bytes

```rust extern crate lazybytescast; use lazybytescast::slice::{ ByteSlice, ByteIndex };

fn main() { let some_int = 666;

for (idx, byte) in some_int.byte_slice().iter().enumerate() {
    assert_eq!(some_int.byte(idx).unwrap(), *byte);
    println!("bytes[{}]={}", idx, byte);
}

} ```

Cast bytes to integer

```rust extern crate lazybytescast; use lazybytescast::from::{ bytes_cast };

fn main() { let bytes = vec![127, 150, 152, 0];

if let Some(int) = bytes_cast::<u32>(&bytes) {
    println!("bytes={}", int);
}
else {
    println!("Couldn't extract integer from bytes");
}

} ```

Cast integer to bytes

```rust extern crate lazybytescast; use lazybytescast::to::{ ToBytesCast };

fn main() { let some_int = 666;

let bytes = some_int.to_bytes();

println!("bytes={:?}", bytes);

} ```