#![cfg_attr(not(doctest), doc = include_str!("../README.md"))]
#![no_std]
#[doc(no_inline)]
pub use arbitrary_int;
pub use bilge_impl::{bitsize, bitsize_internal, BinaryBits, DebugBits, DefaultBits, FromBits, TryFromBits};
pub mod prelude {
#[rustfmt::skip]
#[doc(no_inline)]
pub use super::{
bitsize, Bitsized,
FromBits, TryFromBits, DebugBits, BinaryBits, DefaultBits,
arbitrary_int::*,
};
}
pub trait Bitsized {
type ArbitraryInt;
const BITS: usize;
const MAX: Self::ArbitraryInt;
}
pub unsafe trait Filled: Bitsized {}
unsafe impl<T> Filled for T where T: Bitsized + From<<T as Bitsized>::ArbitraryInt> {}
pub const fn assume_filled<T: Filled>() {}
#[non_exhaustive]
#[derive(Debug, PartialEq)]
pub struct BitsError;
pub const fn give_me_error() -> BitsError {
BitsError
}
impl<BaseType, const BITS: usize> Bitsized for arbitrary_int::UInt<BaseType, BITS>
where
arbitrary_int::UInt<BaseType, BITS>: arbitrary_int::Number,
{
type ArbitraryInt = Self;
const BITS: usize = BITS;
const MAX: Self::ArbitraryInt = <Self as arbitrary_int::Number>::MAX;
}
macro_rules! bitsized_impl {
($(($name:ident, $bits:expr)),+) => {
$(
impl Bitsized for $name {
type ArbitraryInt = Self;
const BITS: usize = $bits;
const MAX: Self::ArbitraryInt = <Self as arbitrary_int::Number>::MAX;
}
)+
};
}
bitsized_impl!((u8, 8), (u16, 16), (u32, 32), (u64, 64), (u128, 128));
impl Bitsized for bool {
type ArbitraryInt = arbitrary_int::u1;
const BITS: usize = 1;
const MAX: Self::ArbitraryInt = <arbitrary_int::u1 as arbitrary_int::Number>::MAX;
}