use crate::{
Nat,
array::{helper::*, *},
condty::CondResult,
expr,
internals::ArraySealed,
};
unsafe impl<T, const N: usize> Array for [T; N]
where
crate::consts::Usize<N>: crate::NatExpr,
{
type Item = T;
type Length = crate::Eval<crate::consts::Usize<N>>;
}
impl<T, const N: usize> ArraySealed for [T; N] where crate::consts::Usize<N>: crate::NatExpr {}
unsafe impl<A: Array> Array for core::mem::MaybeUninit<A> {
type Item = core::mem::MaybeUninit<A::Item>;
type Length = A::Length;
}
impl<A: Array> ArraySealed for core::mem::MaybeUninit<A> {}
unsafe impl<A: Array> Array for ArrApi<A> {
type Item = A::Item;
type Length = A::Length;
}
impl<A: Array> ArraySealed for ArrApi<A> {}
unsafe impl<T, A: Array<Item = T>, B: Array<Item = T>> Array for ArrConcat<A, B> {
type Item = T;
type Length = crate::Eval<crate::expr::Add<A::Length, B::Length>>;
}
impl<T, A: Array<Item = T>, B: Array<Item = T>> ArraySealed for ArrConcat<A, B> {}
unsafe impl<A: Array<Item = B>, B: Array> Array for ArrFlatten<A> {
type Item = B::Item;
type Length = crate::Eval<crate::expr::Mul<A::Length, B::Length>>;
}
impl<A: Array<Item = B>, B: Array> ArraySealed for ArrFlatten<A> {}
mod base;
mod cmp;
mod convert_impl;
mod core_impl;
mod iter;
mod tuple_convert;
impl<T, N: Nat, A> ArrApi<A>
where
A: Array<Item = T, Length = N>,
{
pub const fn new(inner: A) -> Self {
Self { inner }
}
#[track_caller]
pub const fn length() -> usize {
arr_len::<Self>()
}
pub const fn into_inner(self) -> A {
self.retype()
}
#[track_caller]
pub fn from_fn<F: FnMut(usize) -> T>(mut f: F) -> Self {
let _ = Self::length();
let mut out = ArrVecApi::new();
while !out.is_full() {
out.push(f(out.len()));
}
out.assert_full()
}
pub const fn retype<Dst>(self) -> Dst
where
Dst: Array<Item = T, Length = N>,
{
arr_api::retype(self)
}
pub const fn try_retype<Dst: Array<Item = T>>(
self,
) -> CondResult<expr::Eq<N, Dst::Length>, Dst, Self> {
arr_api::try_retype(self)
}
pub const fn concat_arr<Rhs>(self, rhs: Rhs) -> ArrApi<ArrConcat<A, Rhs>>
where
Rhs: Array<Item = T>,
{
ArrApi::new(ArrConcat(self.into_inner(), rhs))
}
pub const fn flatten(self) -> ArrApi<ArrFlatten<A>>
where
T: Array,
{
ArrApi::new(ArrFlatten(self.into_inner()))
}
}