#![no_std]
#![warn(missing_docs)]
mod buf;
mod error;
mod read;
mod write;
pub use buf::BitBuf;
pub use error::Error;
pub type Result<T> = core::result::Result<T, Error>;
pub trait Storage {
fn as_bytes(&self) -> &[u8];
}
pub trait StorageMut: Storage {
fn as_bytes_mut(&mut self) -> &mut [u8];
}
impl<const N: usize> Storage for [u8; N] {
#[inline(always)]
fn as_bytes(&self) -> &[u8] {
self
}
}
impl<const N: usize> StorageMut for [u8; N] {
#[inline(always)]
fn as_bytes_mut(&mut self) -> &mut [u8] {
self
}
}
impl<const N: usize> Storage for &[u8; N] {
#[inline(always)]
fn as_bytes(&self) -> &[u8] {
*self
}
}
impl<const N: usize> Storage for &mut [u8; N] {
#[inline(always)]
fn as_bytes(&self) -> &[u8] {
*self
}
}
impl<const N: usize> StorageMut for &mut [u8; N] {
#[inline(always)]
fn as_bytes_mut(&mut self) -> &mut [u8] {
*self
}
}
impl Storage for &[u8] {
#[inline(always)]
fn as_bytes(&self) -> &[u8] {
self
}
}
impl Storage for &mut [u8] {
#[inline(always)]
fn as_bytes(&self) -> &[u8] {
self
}
}
impl StorageMut for &mut [u8] {
#[inline(always)]
fn as_bytes_mut(&mut self) -> &mut [u8] {
self
}
}
macro_rules! ensure {
($cond:expr $(,)? $(; $($tt:tt)*)?) => {
#[allow(clippy::macro_metavars_in_unsafe)]
unsafe {
$(
#[cfg(test)]
::core::assert!($cond, $($tt)*);
)?
$(
#[cfg(not(test))]
::core::debug_assert!($cond, $($tt)*);
)?
::core::hint::assert_unchecked($cond);
}
};
}
use ensure;