1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//!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
//!use lazy_bytes_cast::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
//!use lazy_bytes_cast::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
//!use lazy_bytes_cast::to::{ToBytesCast};
//!
//!fn main() {
//!    let some_int = 666;
//!
//!    let bytes = some_int.to_bytes();
//!
//!    println!("bytes={:?}", bytes);
//!}
//!```

#![warn(missing_docs)]
#![cfg_attr(feature = "cargo-clippy", allow(clippy::style))]
#![cfg_attr(not(feature = "std"), no_std)]

#[cfg(not(feature = "std"))]
extern crate alloc;

pub mod to;
pub mod from;
pub mod slice;
pub mod array;