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