#![allow(deprecated)]
#![doc = include_str!("../doc/macros.md")]
#[macro_use]
#[doc(hidden)]
pub mod internal;
mod tests;
#[macro_export]
#[doc = include_str!("../doc/macros/BitArr_type.md")]
macro_rules! BitArr {
(for $len:expr, in $store:ty, $order:ty $(,)?) => {
$crate::array::BitArray::<
[$store; $crate::mem::elts::<$store>($len)], $order
>
};
(for $len:expr, in $store:ty $(,)?) => {
$crate::BitArr!(for $len, in $store, $crate::order::Lsb0)
};
(for $len:expr) => {
$crate::BitArr!(for $len, in usize)
};
}
#[macro_export]
#[doc = include_str!("../doc/macros/bitarr_value.md")]
macro_rules! bitarr {
(const Cell<$store:ident>, $order:ident; $($val:expr),* $(,)?) => {{
const ELTS: usize = $crate::__count_elts!($store; $($val),*);
type Data = [Cell<$store>; ELTS];
const DATA: Data = $crate::__encode_bits!(Cell<$store>, $order; $($val),*);
type This = $crate::array::BitArray<Data, $order>;
This { data: DATA, ..This::ZERO }
}};
(const $store:ident, $order:ident; $($val:expr),* $(,)?) => {{
const ELTS: usize = $crate::__count_elts!($store; $($val),*);
type Data = [$store; ELTS];
const DATA: Data = $crate::__encode_bits!($store, $order; $($val),*);
type This = $crate::array::BitArray<Data, $order>;
This { data: DATA, ..This::ZERO }
}};
(const $store:ty, $order:ty; $val:expr; $len:expr) => {{
use $crate::macros::internal::core;
type Mem = <$store as $crate::store::BitStore>::Mem;
const ELTS: usize = $crate::mem::elts::<$store>($len);
const ELEM: Mem = $crate::__extend_bool!($val, $store);
const DATA: [Mem; ELTS] = [ELEM; ELTS];
type This = $crate::array::BitArray<[$store; ELTS], $order>;
unsafe { core::mem::transmute::<_, This>(DATA) }
}};
(const $val:expr; $len:expr) => {{
$crate::bitarr!(const usize, $crate::order::Lsb0; $val; $len)
}};
(const $($val:expr),* $(,)?) => {{
$crate::bitarr!(const usize, Lsb0; $($val),*)
}};
(Cell<$store:ident>, $order:ident; $($val:expr),* $(,)?) => {{
use $crate::macros::internal::core;
type Celled = core::cell::Cell<$store>;
const ELTS: usize = $crate::__count_elts!($store; $($val),*);
type Data = [Celled; ELTS];
type This = $crate::array::BitArray<Data, $order>;
This::new($crate::__encode_bits!(Cell<$store>, $order; $($val),*))
}};
(Cell<$store:ident>, $order:path; $($val:expr),* $(,)?) => {{
use $crate::macros::internal::core;
type Celled = core::cell::Cell<$store>;
const ELTS: usize = $crate::__count_elts!($store; $($val),*);
type This = $crate::array::BitArray<[Celled; ELTS], $order>;
This::new($crate::__encode_bits!(Cell<$store>, $order; $($val),*))
}};
($store:ident, $order:ident; $($val:expr),* $(,)?) => {{
const ELTS: usize = $crate::__count_elts!($store; $($val),*);
type This = $crate::array::BitArray<[$store; ELTS], $order>;
This::new($crate::__encode_bits!($store, $order; $($val),*))
}};
($store:ident, $order:path; $($val:expr),* $(,)?) => {{
const ELTS: usize = $crate::__count_elts!($store; $($val),*);
type This = $crate::array::BitArray<[$store; ELTS], $order>;
This::new($crate::__encode_bits!($store, $order; $($val),*))
}};
($store:ty, $order:ty; $val:expr; $len:expr) => {{
$crate::bitarr!(const $store, $order; $val; $len)
}};
($val:expr; $len:expr) => {{
$crate::bitarr!(const $val; $len)
}};
($($val:expr),* $(,)?) => {
$crate::bitarr!(usize, Lsb0; $($val),*)
};
}
#[macro_export]
#[doc = include_str!("../doc/macros/bits.md")]
macro_rules! bits {
(static mut Cell<$store:ident>, $order:ty; $val:expr; $len:expr) => {{
use $crate::macros::internal::core;
type Celled = core::cell::Cell<$store>;
static mut DATA: $crate::BitArr!(for $len, in Celled, $order) =
$crate::bitarr!(const Cell<$store>, $order; $val; $len);
&mut DATA[.. $len]
}};
(static mut $store:ident, $order:ident; $val:expr; $len:expr) => {{
static mut DATA: $crate::BitArr!(for $len, in $store, $order) =
$crate::bitarr!(const $store, $order; $val; $len);
DATA.get_unchecked_mut(.. $len)
}};
(static mut Cell<$store:ident>, $order:ident; $($val:expr),* $(,)?) => {{
use $crate::macros::internal::core;
type Celled = core::cell::Cell<$store>;
const BITS: usize = $crate::__count!($($val),*);
static mut DATA: $crate::BitArr!(for BITS, in $store, $order) =
$crate::bitarr!(const $store, $order; $($val),*);
&mut *(
DATA.get_unchecked_mut(.. BITS)
as *mut $crate::slice::BitSlice<$store, $order>
as *mut $crate::slice::BitSlice<Celled, $order>
)
}};
(static mut $store:ident, $order:ident; $($val:expr),* $(,)?) => {{
const BITS: usize = $crate::__count!($($val),*);
static mut DATA: $crate::BitArr!(for BITS, in $store, $order) =
$crate::bitarr!(const $store, $order; $($val),*);
DATA.get_unchecked_mut(.. BITS)
}};
(static mut $val:expr; $len:expr) => {{
static mut DATA: $crate::BitArr!(for $len) =
$crate::bitarr!(const usize, $crate::order::Lsb0; $val; $len);
DATA.get_unchecked_mut(.. $len)
}};
(static mut $($val:expr),* $(,)?) => {{
$crate::bits!(static mut usize, Lsb0; $($val),*)
}};
(static Cell<$store:ident>, $order:ty; $val:expr; $len:expr) => {{
use $crate::macros::internal::core;
type Celled = core::cell::Cell<$store>;
static DATA: $crate::BitArr!(for $len, in $store, $order) =
$crate::bitarr!(const $store, $order; $val; $len);
unsafe {
&*(
DATA.get_unchecked(.. $len)
as *const $crate::slice::BitSlice<$store, $order>
as *const $crate::slice::BitSlice<Celled, $order>
)
}
}};
(static Cell<$store:ident>, $order:ident; $($val:expr),* $(,)?) => {{
use $crate::macros::internal::core;
type Celled = core::cell::Cell<$store>;
const BITS: usize = $crate::__count!($($val),*);
static DATA: $crate::BitArr!(for BITS, in $store, $order) =
$crate::bitarr!(const $store, $order; $($val),*);
unsafe {
&*(
DATA.get_unchecked(.. BITS)
as *const $crate::slice::BitSlice<$store, $order>
as *const $crate::slice::BitSlice<Celled, $order>
)
}
}};
(static $store:ident, $order:ident; $val:expr; $len:expr) => {{
static DATA: $crate::BitArr!(for $len, in $store, $order) =
$crate::bitarr!(const $store, $order; $val; $len);
unsafe { DATA.get_unchecked(.. $len) }
}};
(static $val:expr; $len:expr) => {{
static DATA: $crate::BitArr!(for $len) =
$crate::bitarr!(const usize, $crate::order::Lsb0; $val; $len);
unsafe { DATA.get_unchecked(.. $len) }
}};
(static $store:ident, $order:ident; $($val:expr),* $(,)?) => {{
const BITS: usize = $crate::__count!($($val),*);
static DATA: $crate::BitArr!(for BITS, in $store, $order) =
$crate::bitarr!(const $store, $order; $($val),*);
unsafe { DATA.get_unchecked(.. BITS) }
}};
(static $($val:expr),* $(,)?) => {{
$crate::bits!(static usize, Lsb0; $($val),*)
}};
(mut Cell<$store:ident>, $order:ident; $($val:expr),* $(,)?) => {{
const BITS: usize = $crate::__count!($($val),*);
&mut $crate::bitarr!(Cell<$store>, $order; $($val),*)[.. BITS]
}};
(mut Cell<$store:ident>, $order:path; $($val:expr),* $(,)?) => {{
const BITS: usize = $crate::__count!($($val),*);
&mut $crate::bitarr!(Cell<$store>, $order; $($val),*)[.. BITS]
}};
(mut $store:ident, $order:ident; $($val:expr),* $(,)?) => {{
const BITS: usize = $crate::__count!($($val),*);
&mut $crate::bitarr!($store, $order; $($val),*)[.. BITS]
}};
(mut $store:ident, $order:path; $($val:expr),* $(,)?) => {{
const BITS: usize = $crate::__count!($($val),*);
&mut $crate::bitarr!($store, $order; $($val),*)[.. BITS]
}};
(mut $store:ty, $order:ty; $val:expr; $len:expr) => {{
&mut $crate::bitarr!($store, $order; $val; $len)[.. $len]
}};
(mut $val:expr; $len:expr) => {
$crate::bits!(mut usize, $crate::order::Lsb0; $val; $len)
};
(mut $($val:expr),* $(,)?) => {
$crate::bits!(mut usize, Lsb0; $($val),*)
};
($store:ty, $order:ty; $val:expr; $len:expr) => {{
&$crate::bitarr!($store, $order; $val; $len)[.. $len]
}};
(Cell<$store:ident>, $order:ident; $($val:expr),* $(,)?) => {{
const BITS: usize = $crate::__count!($($val),*);
&$crate::bitarr!(Cell<$store>, $order; $($val),*)[.. BITS]
}};
($store:ident, $order:ident; $($val:expr),* $(,)?) => {{
const BITS: usize = $crate::__count!($($val),*);
&$crate::bitarr!($store, $order; $($val),*)[.. BITS]
}};
(Cell<$store:ident>, $order:path; $($val:expr),* $(,)?) => {{
const BITS: usize = $crate::__count!($($val),*);
&$crate::bitarr!(Cell<$store>, $order; $($val),*)[.. BITS]
}};
($store:ident, $order:path; $($val:expr),* $(,)?) => {{
const BITS: usize = $crate::__count!($($val),*);
&$crate::bitarr!($store, $order; $($val),*)[.. BITS]
}};
($val:expr; $len:expr) => {
$crate::bits!(usize, $crate::order::Lsb0; $val; $len)
};
($($val:expr),* $(,)?) => {
$crate::bits!(usize, Lsb0; $($val),*)
};
}
#[macro_export]
#[cfg(feature = "alloc")]
#[doc = include_str!("../doc/macros/bitvec.md")]
macro_rules! bitvec {
($store:ty, $order:ty; $val:expr; $len:expr) => {
$crate::vec::BitVec::<$store, $order>::repeat($val != 0, $len)
};
(Cell<$store:ident>, $order:ident $($rest:tt)*) => {
$crate::vec::BitVec::from_bitslice($crate::bits!(Cell<$store>, $order $($rest)*))
};
($val:expr; $len:expr) => {
$crate::bitvec!(usize, $crate::order::Lsb0; $val; $len)
};
($($arg:tt)*) => {
$crate::vec::BitVec::from_bitslice($crate::bits!($($arg)*))
};
}
#[macro_export]
#[cfg(feature = "alloc")]
#[doc = include_str!("../doc/macros/bitbox.md")]
macro_rules! bitbox {
($($arg:tt)*) => {
$crate::bitvec!($($arg)*).into_boxed_bitslice()
};
}