macro_rules! methods_base {
($inner_t:ident, $n:expr) => {
pub fn len(&self) -> usize {
self.0.len()
}
pub fn is_empty(&self) -> bool {
self.0.is_empty()
}
pub fn element_offset(&self, element: &$inner_t) -> Option<usize> {
self.0.element_offset(element)
}
pub fn iter(&self) -> Iter<'_, $inner_t> {
self.0.iter()
}
pub fn iter_mut(&mut self) -> IterMut<'_, $inner_t> {
self.0.iter_mut()
}
pub fn fill_with<F: FnMut() -> $inner_t>(&mut self, f: F) -> () {
self.0.fill_with(f)
}
pub fn first(&self) -> Option<&$inner_t> {
self.0.first()
}
pub fn first_mut(&mut self) -> Option<&mut $inner_t> {
self.0.first_mut()
}
pub fn last(&self) -> Option<&$inner_t> {
self.0.last()
}
pub fn last_mut(&mut self) -> Option<&mut $inner_t> {
self.0.last_mut()
}
pub fn as_slice(&self) -> &[$inner_t] {
self.0.as_slice()
}
pub fn as_mut_slice(&mut self) -> &mut [$inner_t] {
self.0.as_mut_slice()
}
pub fn as_array<const N: usize>(&self) -> Option<&[$inner_t; N]> {
self.0.as_array()
}
pub fn as_mut_array<const N: usize>(&mut self) -> Option<&mut [$inner_t; N]> {
self.0.as_mut_array()
}
pub fn each_ref(&self) -> [&$inner_t; $n] {
self.0.each_ref()
}
pub fn each_mut(&mut self) -> [&mut $inner_t; $n] {
self.0.each_mut()
}
pub fn get(&self, index: usize) -> Option<&$inner_t> {
self.0.get(index)
}
pub fn get_mut(&mut self, index: usize) -> Option<&mut $inner_t> {
self.0.get_mut(index)
}
pub fn as_chunks<const N: usize>(&self) -> (&[[$inner_t; N]], &[$inner_t]) {
self.0.as_chunks()
}
pub fn as_chunks_mut<const N: usize>(&mut self) -> (&mut [[$inner_t; N]], &mut [$inner_t]) {
self.0.as_chunks_mut()
}
pub fn split<F: FnMut(&$inner_t) -> bool>(&self, pred: F) -> Split<'_, $inner_t, F> {
self.0.split(pred)
}
pub fn split_mut<F: FnMut(&$inner_t) -> bool>(
&mut self,
pred: F,
) -> SplitMut<'_, $inner_t, F> {
self.0.split_mut(pred)
}
pub fn split_at(&self, mid: usize) -> (&[$inner_t], &[$inner_t]) {
self.0.split_at(mid)
}
pub fn split_at_mut(&mut self, mid: usize) -> (&mut [$inner_t], &mut [$inner_t]) {
self.0.split_at_mut(mid)
}
pub fn split_at_checked(&self, mid: usize) -> Option<(&[$inner_t], &[$inner_t])> {
self.0.split_at_checked(mid)
}
pub fn split_at_mut_checked(
&mut self,
mid: usize,
) -> Option<(&mut [$inner_t], &mut [$inner_t])> {
self.0.split_at_mut_checked(mid)
}
pub fn split_first(&self) -> Option<(&$inner_t, &[$inner_t])> {
self.0.split_first()
}
pub fn split_first_mut(&mut self) -> Option<(&mut $inner_t, &mut [$inner_t])> {
self.0.split_first_mut()
}
pub fn split_last(&self) -> Option<(&$inner_t, &[$inner_t])> {
self.0.split_last()
}
pub fn split_last_mut(&mut self) -> Option<(&mut $inner_t, &mut [$inner_t])> {
self.0.split_last_mut()
}
pub fn split_inclusive<F: FnMut(&$inner_t) -> bool>(
&self,
f: F,
) -> SplitInclusive<'_, $inner_t, F> {
self.0.split_inclusive(f)
}
pub fn split_inclusive_mut<F: FnMut(&$inner_t) -> bool>(
&mut self,
f: F,
) -> SplitInclusiveMut<'_, $inner_t, F> {
self.0.split_inclusive_mut(f)
}
};
}
macro_rules! methods_partial_eq {
($inner_t:ident) => {
pub fn contains(&self, x: &$inner_t) -> bool {
self.0.contains(x)
}
};
}
macro_rules! methods_copy {
($inner_t:ident, $n:expr) => {
pub fn map<F: FnMut($inner_t) -> U, U>(self, f: F) -> [U; $n] {
self.0.map(f)
}
pub fn repeat(&mut self, n: usize) -> Vec<$inner_t> {
self.0.repeat(n)
}
pub fn copy_from_slice(&mut self, src: &[$inner_t]) -> () {
self.0.copy_from_slice(src)
}
};
}
macro_rules! methods_clone {
($inner_t:ident, $n:expr) => {
pub fn fill(&mut self, value: $inner_t) -> () {
self.0.fill(value)
}
pub fn to_vec(&self) -> Vec<$inner_t> {
self.0.to_vec()
}
pub fn clone_from_slice(&mut self, src: &[$inner_t]) -> () {
self.0.clone_from_slice(src)
}
pub fn clone_into(&mut self, target: &mut Self) -> () {
self.0.clone_into(&mut target.0)
}
};
}
macro_rules! method_id {
($inner_t:ident, $id:ident) => {
pub fn id(self, id: &$id) -> $inner_t {
self.0[id.as_index()]
}
};
}
macro_rules! method_id_ref {
($inner_t:ident, $id:ident) => {
pub fn id_ref(&self, id: &$id) -> &$inner_t {
&self.0[id.as_index()]
}
};
}
macro_rules! method_id_mut {
($inner_t:ident, $id:ident) => {
pub fn id_mut(&mut self, id: &$id) -> &mut $inner_t {
&mut self.0[id.as_index()]
}
};
}
macro_rules! generic_newtype_method_delegate {
($name:ident, $n:expr) => {
impl<T> $name<T> {
methods_base!(T, $n);
}
impl<T: PartialEq> $name<T> {
methods_partial_eq!(T);
}
impl<T: Copy> $name<T> {
methods_copy!(T, $n);
}
impl<T: Clone> $name<T> {
methods_clone!(T, $n);
}
};
}
macro_rules! generic_newtype_unbox {
($name:ident, $n:expr) => {
impl<T> $name<T> {
pub fn unbox(self) -> [T; $n] {
*self.0
}
pub fn unbox_ref(&self) -> &[T; $n] {
&*self.0
}
pub fn unbox_mut(&mut self) -> &mut [T; $n] {
&mut *self.0
}
}
};
}
macro_rules! generic_newtype_id_lookups {
($name:ident, $id:ident) => {
impl<T> $name<T> {
method_id_ref!(T, $id);
method_id_mut!(T, $id);
}
impl<T: Copy> $name<T> {
method_id!(T, $id);
}
};
}
macro_rules! generic_newtype_asref {
($name:ident) => {
impl<T> AsRef<$name<T>> for $name<T> {
fn as_ref(&self) -> &$name<T> {
self
}
}
};
}
macro_rules! generic_newtype_asmut {
($name:ident) => {
impl<T> AsMut<$name<T>> for $name<T> {
fn as_mut(&mut self) -> &mut $name<T> {
self
}
}
};
}
macro_rules! generic_newtype_deref {
($name:ident, $n:expr) => {
impl<T> Deref for $name<T> {
type Target = [T; $n];
fn deref(&self) -> &Self::Target {
&self.0
}
}
};
}
macro_rules! generic_newtype_deref_mut {
($name:ident) => {
impl<T> DerefMut for $name<T> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}
};
}
macro_rules! generic_newtype_index {
($name:ident) => {
impl<T, I> Index<I> for $name<T>
where
[T]: Index<I>,
{
type Output = <[T] as Index<I>>::Output;
#[inline]
fn index(&self, index: I) -> &Self::Output {
Index::index(&self.0 as &[T], index)
}
}
};
}
macro_rules! generic_newtype_index_mut {
($name:ident) => {
impl<T, I> IndexMut<I> for $name<T>
where
[T]: IndexMut<I>,
{
#[inline]
fn index_mut(&mut self, index: I) -> &mut Self::Output {
IndexMut::index_mut(&mut self.0 as &mut [T], index)
}
}
};
}
macro_rules! generic_newtype_into_iter {
($name:ident, $n:expr) => {
impl<T> IntoIterator for $name<T> {
type Item = T;
type IntoIter = std::array::IntoIter<Self::Item, $n>;
fn into_iter(self) -> Self::IntoIter {
self.0.into_iter()
}
}
};
}
pub(crate) use generic_newtype_asmut;
pub(crate) use generic_newtype_asref;
pub(crate) use generic_newtype_deref;
pub(crate) use generic_newtype_deref_mut;
pub(crate) use generic_newtype_id_lookups;
pub(crate) use generic_newtype_index;
pub(crate) use generic_newtype_index_mut;
pub(crate) use generic_newtype_into_iter;
pub(crate) use generic_newtype_method_delegate;
pub(crate) use generic_newtype_unbox;
pub(crate) use method_id;
pub(crate) use method_id_mut;
pub(crate) use method_id_ref;
pub(crate) use methods_base;
pub(crate) use methods_clone;
pub(crate) use methods_copy;
pub(crate) use methods_partial_eq;