static_bytes/
lib.rs

1//! The aim of this crate is to improve user experience when working with static bytes.
2//! Look at this pseudo code example to understand problem with `&mut [u8]` and `bytes::buf::BufMut`
3//! ```compile_fail
4//! let mut fixed_storage = [u8; 16];
5//! let mut slice = fixed_storage[..];
6//! let len_before = slice.len();
7//! // declaration fn encode(&self, buf: &mut dyn BufMut);
8//! frame.encode(&mut slice);
9//! let len = len_before - slice.len();
10//! let filled_bytes = fixed_storage[..len];
11//! ```
12//! There are two problems with code above:
13//! - it will panic if encode want to use more than 16 bytes!
14//! - it is boilerplate
15//!
16//! You can resolve both with `SafeBytesSlice`. For example usage see
17//! [docs](https://docs.rs/static-bytes/0.2/static_bytes/struct.SafeBytesSlice.html).
18//!
19//! ## Compatibility with bytes
20//! - v0.1.x is compatible with bytes >=0.5.0, <0.6.0
21//! - v0.2.x is compatible with bytes >=0.6.0, <0.7.0
22//! - v0.3.x is compatible with bytes >=0.1.0, <2.0.0
23//!
24
25#![deny(missing_docs)]
26#![no_std]
27
28mod bytes_slice;
29pub mod error;
30pub use bytes_slice::SafeBytesSlice;