#[macro_export]
macro_rules! staticvec {
($($val:expr),* $(,)*) => {
$crate::StaticVec::new_from_const_array([$($val),*])
};
($val:expr; $n:expr) => {
$crate::StaticVec::new_from_const_array([$val; $n])
};
}
#[macro_export]
#[rustfmt::skip]
macro_rules! staticstring {
($val:expr) => {{
const CAP: usize = $val.len();
unsafe {
$crate::StaticString::<CAP>::__new_from_staticvec(
$crate::StaticVec::<u8, CAP>::__new_from_const_str($val)
)
}
};};
($val:expr, $n:expr) => {{
unsafe {
$crate::StaticString::<$n>::__new_from_staticvec(
$crate::StaticVec::<u8, $n>::__new_from_const_str($val)
)
}
};};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __staticsort {
($type:ty, $low:expr, $high:expr, $len:expr, $values:expr) => {{
match $len {
0 => $values,
_ => {
#[inline]
const fn static_sort(
mut values: [$type; $len],
mut low: isize,
mut high: isize,
) -> [$type; $len] {
if high - low <= 0 {
return values;
}
loop {
let mut i = low;
let mut j = high;
let p = values[(low + ((high - low) >> 1)) as usize];
loop {
while values[i as usize] < p {
i += 1;
}
while values[j as usize] > p {
j -= 1;
}
if i <= j {
if i != j {
let q = values[i as usize];
values[i as usize] = values[j as usize];
values[j as usize] = q;
}
i += 1;
j -= 1;
}
if i > j {
break;
}
}
if j - low < high - i {
if low < j {
values = static_sort(values, low, j);
}
low = i;
} else {
if i < high {
values = static_sort(values, i, high)
}
high = j;
}
if low >= high {
break;
}
}
values
}
static_sort($values, $low, $high)
}
}
};};
}
#[macro_export]
macro_rules! sortedstaticvec {
(@put_one $val:expr) => (1);
($type: ty, [$($val:expr),* $(,)*]) => {{
const LEN: usize = 0$(+sortedstaticvec!(@put_one $val))*;
match LEN {
0 => $crate::StaticVec::new(),
_ => $crate::StaticVec::new_from_const_array(
$crate::__staticsort!(
$type,
0,
(LEN as isize) - 1,
LEN,
[$($val),*]
)
),
}
};};
}
macro_rules! impl_extend_ex {
($var_a:tt, $var_b:tt) => {
#[allow(unused_parens)]
#[inline]
default fn extend_ex(&mut self, iter: I) {
let mut it = iter.into_iter();
let mut i = self.length;
while i < N {
if let Some($var_a) = it.next() {
unsafe {
self.mut_ptr_at_unchecked(i).write($var_b);
}
} else {
break;
}
i += 1;
}
self.length = i;
}
};
}
macro_rules! impl_from_iter_ex {
($var_a:tt, $var_b:tt) => {
#[allow(unused_parens)]
#[inline]
default fn from_iter_ex(iter: I) -> Self {
let mut res = Self::new_data_uninit();
let mut it = iter.into_iter();
let mut i = 0;
while i < N {
if let Some($var_a) = it.next() {
unsafe {
Self::first_ptr_mut(&mut res).add(i).write($var_b);
}
} else {
break;
}
i += 1;
}
Self {
data: res,
length: i,
}
}
};
}
macro_rules! impl_partial_eq_with_as_slice {
($left:ty, $right:ty) => {
impl<T1, T2: PartialEq<T1>, const N1: usize, const N2: usize> PartialEq<$left> for $right {
#[inline(always)]
fn eq(&self, other: &$left) -> bool {
self.as_slice() == other.as_slice()
}
#[allow(clippy::partialeq_ne_impl)]
#[inline(always)]
fn ne(&self, other: &$left) -> bool {
self.as_slice() != other.as_slice()
}
}
};
}
macro_rules! impl_partial_eq_with_get_unchecked {
($left:ty, $right:ty) => {
impl<T1, T2: PartialEq<T1>, const N1: usize, const N2: usize> PartialEq<$left> for $right {
#[inline(always)]
fn eq(&self, other: &$left) -> bool {
unsafe { self.as_slice() == other.get_unchecked(..) }
}
#[allow(clippy::partialeq_ne_impl)]
#[inline(always)]
fn ne(&self, other: &$left) -> bool {
unsafe { self.as_slice() != other.get_unchecked(..) }
}
}
};
}
macro_rules! impl_partial_eq_with_equals_no_deref {
($left:ty, $right:ty) => {
impl<T1, T2: PartialEq<T1>, const N: usize> PartialEq<$left> for $right {
#[inline(always)]
fn eq(&self, other: &$left) -> bool {
self.as_slice() == other
}
#[allow(clippy::partialeq_ne_impl)]
#[inline(always)]
fn ne(&self, other: &$left) -> bool {
self.as_slice() != other
}
}
};
}
macro_rules! impl_partial_eq_with_equals_deref {
($left:ty, $right:ty) => {
impl<T1, T2: PartialEq<T1>, const N: usize> PartialEq<$left> for $right {
#[inline(always)]
fn eq(&self, other: &$left) -> bool {
self.as_slice() == *other
}
#[allow(clippy::partialeq_ne_impl)]
#[inline(always)]
fn ne(&self, other: &$left) -> bool {
self.as_slice() != *other
}
}
};
}
macro_rules! impl_partial_ord_with_as_slice {
($left:ty, $right:ty) => {
impl<T1, T2: PartialOrd<T1>, const N1: usize, const N2: usize> PartialOrd<$left> for $right {
#[inline(always)]
fn partial_cmp(&self, other: &$left) -> Option<Ordering> {
partial_compare(self.as_slice(), other.as_slice())
}
}
};
}
macro_rules! impl_partial_ord_with_get_unchecked {
($left:ty, $right:ty) => {
impl<T1, T2: PartialOrd<T1>, const N1: usize, const N2: usize> PartialOrd<$left> for $right {
#[inline(always)]
fn partial_cmp(&self, other: &$left) -> Option<Ordering> {
unsafe { partial_compare(self.as_slice(), other.get_unchecked(..)) }
}
}
};
}
macro_rules! impl_partial_ord_with_as_slice_against_slice {
($left:ty, $right:ty) => {
impl<T1, T2: PartialOrd<T1>, const N: usize> PartialOrd<$left> for $right {
#[inline(always)]
fn partial_cmp(&self, other: &$left) -> Option<Ordering> {
partial_compare(self.as_slice(), other)
}
}
};
}