#[cfg(feature = "uninit")]
use crate::uninit::*;
#[cfg(feature = "unwrap")]
use crate::unwrap::*;
use crate::{fold::Foldable, foreach::Foreach, macros::*, ops::*, predicate::*, search::*};
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
#[cfg(feature = "uninit")]
use std::mem::MaybeUninit;
use std::{
ops::{
Add, AddAssign, BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, Div,
DivAssign, Mul, MulAssign, Neg, Not, Rem, RemAssign, Shl, ShlAssign, Shr, ShrAssign, Sub,
SubAssign,
},
pin::Pin,
};
use tuplez_macros::tuple_traits_impl;
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Unit;
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Tuple<First, Other>(
pub First,
).
pub Other,
);
pub trait TupleLike {
type AsRefOutput<'a>: TupleLike
where
Self: 'a;
type AsMutOutput<'a>: TupleLike
where
Self: 'a;
type AsPtrOutput: TupleLike;
type AsMutPtrOutput: TupleLike;
type AsPinRefOutput<'a>: TupleLike
where
Self: 'a;
type AsPinMutOutput<'a>: TupleLike
where
Self: 'a;
type PushFrontOutput<T>: TupleLike;
type PushBackOutput<T>: TupleLike;
type RevOutput: TupleLike;
type JoinOutput<T>: TupleLike
where
T: TupleLike;
type ToSomeOutput: TupleLike;
type ToOkOutput<E>: TupleLike;
type ToTupleOutput: TupleLike;
#[cfg(feature = "uninit")]
#[cfg_attr(docsrs, doc(cfg(feature = "uninit")))]
type Uninit: TupleLike;
const LEN: usize;
fn len(&self) -> usize {
Self::LEN
}
fn is_empty(&self) -> bool {
Self::LEN == 0
}
fn by_ref(&mut self) -> &mut Self
where
Self: Sized,
{
self
}
fn enumerate(self) -> Self::EnumerateOutput
where
Self: Sized + Enumerable,
{
Enumerable::enumerate(self, 0)
}
fn take<T, I>(self) -> (T, Self::TakeRemainder)
where
Self: Search<T, I> + Sized,
{
Search::take(self)
}
fn get_ref<T, I>(&self) -> &T
where
Self: Search<T, I> + Sized,
{
Search::get_ref(self)
}
fn get_mut<T, I>(&mut self) -> &mut T
where
Self: Search<T, I> + Sized,
{
Search::get_mut(self)
}
fn swap<T, I>(&mut self, value: &mut T)
where
Self: Search<T, I>,
{
Search::swap(self, value)
}
fn replace<T, I>(&mut self, value: T) -> T
where
Self: Search<T, I>,
{
Search::replace(self, value)
}
fn map_replace<T, U, F, I>(self, f: F) -> Self::MapReplaceOutput<U>
where
Self: Search<T, I> + Sized,
F: FnOnce(T) -> U,
{
Search::map_replace(self, f)
}
fn subseq<Seq, I>(self) -> Seq
where
Self: Subseq<Seq, I> + Sized,
Seq: TupleLike,
{
Subseq::subseq(self)
}
fn subseq_ref<Seq, I>(&self) -> Seq::AsRefOutput<'_>
where
Self: Subseq<Seq, I> + Sized,
Seq: TupleLike,
{
Subseq::subseq_ref(self)
}
fn subseq_mut<Seq, I>(&mut self) -> Seq::AsMutOutput<'_>
where
Self: Subseq<Seq, I> + Sized,
Seq: TupleLike,
{
Subseq::subseq_mut(self)
}
fn swap_subseq<Seq, I>(&mut self, subseq: &mut Seq)
where
Seq: TupleLike,
Self: Subseq<Seq, I>,
{
Subseq::swap_subseq(self, subseq)
}
fn replace_subseq<Seq, I>(&mut self, subseq: Seq) -> Seq
where
Seq: TupleLike,
Self: Subseq<Seq, I>,
{
Subseq::replace_subseq(self, subseq)
}
fn map_replace_subseq<Seq, F, I>(self, f: F) -> Self::MapReplaceOutput
where
Seq: TupleLike,
Self: SubseqMapReplace<Seq, F, I> + Sized,
{
SubseqMapReplace::map_replace_subseq(self, f)
}
fn foreach_subseq<Seq, F, I>(self, f: F) -> Self::MapReplaceOutput
where
Seq: TupleLike,
Self: SubseqMapReplace<Seq, F, I> + Sized,
{
SubseqMapReplace::map_replace_subseq(self, f)
}
fn con_subseq<Seq, I>(self) -> Seq
where
Seq: TupleLike,
Self: ConSubseq<Seq, I> + Sized,
{
ConSubseq::con_subseq(self)
}
fn con_subseq_ref<Seq, I>(&self) -> Seq::AsRefOutput<'_>
where
Seq: TupleLike,
Self: ConSubseq<Seq, I>,
{
ConSubseq::con_subseq_ref(self)
}
fn con_subseq_mut<Seq, I>(&mut self) -> Seq::AsMutOutput<'_>
where
Seq: TupleLike,
Self: ConSubseq<Seq, I>,
{
ConSubseq::con_subseq_mut(self)
}
fn swap_con_subseq<Seq, I>(&mut self, subseq: &mut Seq)
where
Seq: TupleLike,
Self: ConSubseq<Seq, I>,
{
ConSubseq::swap_con_subseq(self, subseq)
}
fn replace_con_subseq<Seq, I>(&mut self, subseq: Seq) -> Seq
where
Seq: TupleLike,
Self: ConSubseq<Seq, I>,
{
ConSubseq::replace_con_subseq(self, subseq)
}
fn map_replace_con_subseq<Seq, F, I>(self, f: F) -> Self::MapReplaceOutput
where
Seq: TupleLike,
Self: ConSubseqMapReplace<Seq, F, I> + Sized,
{
ConSubseqMapReplace::map_replace_con_subseq(self, f)
}
fn foreach_con_subseq<Seq, F, I>(self, f: F) -> Self::MapReplaceOutput
where
Seq: TupleLike,
Self: ConSubseqMapReplace<Seq, F, I> + Sized,
{
ConSubseqMapReplace::map_replace_con_subseq(self, f)
}
#[deprecated(since = "0.10.0", note = "Use subseq() or con_subseq() instead")]
fn subset<Seq, I>(self) -> Seq
where
Self: Subseq<Seq, I> + Sized,
Seq: TupleLike,
{
Subseq::subseq(self)
}
#[deprecated(
since = "0.10.0",
note = "Use subseq_ref() or con_subseq_ref() instead"
)]
fn subset_ref<Seq, I>(&self) -> Seq::AsRefOutput<'_>
where
Self: Subseq<Seq, I> + Sized,
Seq: TupleLike,
{
Subseq::subseq_ref(self)
}
#[deprecated(
since = "0.10.0",
note = "Use subseq_mut() or con_subseq_mut() instead"
)]
fn subset_mut<Seq, I>(&mut self) -> Seq::AsMutOutput<'_>
where
Self: Subseq<Seq, I> + Sized,
Seq: TupleLike,
{
Subseq::subseq_mut(self)
}
#[deprecated(
since = "0.10.0",
note = "Use swap(), swap_subseq() or swap_con_subseq() instead"
)]
fn swap_with<Seq, I>(&mut self, subseq: &mut Seq)
where
Seq: TupleLike,
Self: ConSubseq<Seq, I>,
{
ConSubseq::swap_con_subseq(self, subseq)
}
#[deprecated(
since = "0.10.0",
note = "Use replace(), replace_subseq() or replace_con_subseq() instead"
)]
fn replace_with<Seq, I>(&mut self, subseq: Seq) -> Seq
where
Seq: TupleLike,
Self: ConSubseq<Seq, I>,
{
ConSubseq::replace_con_subseq(self, subseq)
}
fn as_ref(&self) -> Self::AsRefOutput<'_>;
fn as_mut(&mut self) -> Self::AsMutOutput<'_>;
fn as_ptr(&self) -> Self::AsPtrOutput;
fn as_mut_ptr(&mut self) -> Self::AsMutPtrOutput;
fn as_pin_ref(self: Pin<&Self>) -> Self::AsPinRefOutput<'_>;
fn as_pin_mut(self: Pin<&mut Self>) -> Self::AsPinMutOutput<'_>;
fn as_deref(&self) -> Self::AsDerefOutput<'_>
where
Self: AsDeref,
{
AsDeref::as_deref(self)
}
fn as_deref_mut(&mut self) -> Self::AsDerefMutOutput<'_>
where
Self: AsDerefMut,
{
AsDerefMut::as_deref_mut(self)
}
fn cloned(&self) -> Self::ClonedOutput
where
Self: Cloned,
{
Cloned::cloned(self)
}
fn copied(&self) -> Self::CopiedOutput
where
Self: Copied,
{
Copied::copied(self)
}
#[cfg(any(feature = "std", feature = "alloc"))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
fn owned(&self) -> Self::OwnedOutput
where
Self: Owned,
{
Owned::owned(self)
}
fn push<T>(self, value: T) -> Self::PushBackOutput<T>;
fn push_front<T>(self, value: T) -> Self::PushFrontOutput<T>;
fn push_back<T>(self, value: T) -> Self::PushBackOutput<T>;
fn pop(self) -> (Self::PopBackOutput, Self::PopBackElement)
where
Self: Poppable + Sized,
{
Poppable::pop(self)
}
fn pop_front(self) -> (Self::PopFrontOutput, Self::PopFrontElement)
where
Self: Poppable + Sized,
{
Poppable::pop_front(self)
}
fn pop_back(self) -> (Self::PopBackOutput, Self::PopBackElement)
where
Self: Poppable + Sized,
{
Poppable::pop_back(self)
}
fn rot_l(self) -> Self::RotLeftOutput
where
Self: Rotatable + Sized,
{
Rotatable::rot_l(self)
}
fn rot_r(self) -> Self::RotRightOutput
where
Self: Rotatable + Sized,
{
Rotatable::rot_r(self)
}
fn rev(self) -> Self::RevOutput;
fn join<T>(self, value: T) -> Self::JoinOutput<T>
where
T: TupleLike;
fn to_some(self) -> Self::ToSomeOutput;
fn to_ok<E>(self) -> Self::ToOkOutput<E>;
fn to_tuple(self) -> Self::ToTupleOutput;
#[cfg(feature = "uninit")]
#[cfg_attr(docsrs, doc(cfg(feature = "uninit")))]
fn uninit() -> Self::Uninit;
#[cfg(feature = "uninit")]
#[cfg_attr(docsrs, doc(cfg(feature = "uninit")))]
fn zeroed() -> Self::Uninit;
#[cfg(feature = "uninit")]
#[cfg_attr(docsrs, doc(cfg(feature = "uninit")))]
fn to_uninit(self) -> Self::Uninit;
#[cfg(feature = "uninit")]
#[cfg_attr(docsrs, doc(cfg(feature = "uninit")))]
unsafe fn uninit_assume_init(self) -> Self::Initialized
where
Self: Uninit + Sized,
{
Uninit::assume_init(self)
}
#[cfg(feature = "uninit")]
#[cfg_attr(docsrs, doc(cfg(feature = "uninit")))]
unsafe fn uninit_assume_init_one<T, I>(self) -> Self::MapReplaceOutput<T>
where
Self: Search<MaybeUninit<T>, I> + Sized,
{
Search::map_replace(self, |x| x.assume_init())
}
#[cfg(feature = "uninit")]
#[cfg_attr(docsrs, doc(cfg(feature = "uninit")))]
unsafe fn uninit_assume_init_read(&self) -> Self::Initialized
where
Self: Uninit,
{
Uninit::assume_init_read(self)
}
#[cfg(feature = "uninit")]
#[cfg_attr(docsrs, doc(cfg(feature = "uninit")))]
unsafe fn uninit_assume_init_read_one<T, I>(&self) -> T
where
Self: Search<MaybeUninit<T>, I>,
{
Search::get_ref(self).assume_init_read()
}
#[cfg(feature = "uninit")]
#[cfg_attr(docsrs, doc(cfg(feature = "uninit")))]
unsafe fn uninit_assume_init_ref(&self) -> <Self::Initialized as TupleLike>::AsRefOutput<'_>
where
Self: Uninit,
{
Uninit::assume_init_ref(self)
}
#[cfg(feature = "uninit")]
#[cfg_attr(docsrs, doc(cfg(feature = "uninit")))]
unsafe fn uninit_assume_init_ref_one<T, I>(&self) -> &T
where
Self: Search<MaybeUninit<T>, I>,
{
Search::get_ref(self).assume_init_ref()
}
#[cfg(feature = "uninit")]
#[cfg_attr(docsrs, doc(cfg(feature = "uninit")))]
unsafe fn uninit_assume_init_mut(&mut self) -> <Self::Initialized as TupleLike>::AsMutOutput<'_>
where
Self: Uninit,
{
Uninit::assume_init_mut(self)
}
#[cfg(feature = "uninit")]
#[cfg_attr(docsrs, doc(cfg(feature = "uninit")))]
unsafe fn uninit_assume_init_mut_one<T, I>(&mut self) -> &mut T
where
Self: Search<MaybeUninit<T>, I>,
{
Search::get_mut(self).assume_init_mut()
}
#[cfg(feature = "uninit")]
#[cfg_attr(docsrs, doc(cfg(feature = "uninit")))]
unsafe fn uninit_assume_init_drop(&mut self)
where
Self: Uninit,
{
Uninit::assume_init_drop(self)
}
#[cfg(feature = "uninit")]
#[cfg_attr(docsrs, doc(cfg(feature = "uninit")))]
unsafe fn uninit_assume_init_drop_one<T, I>(&mut self)
where
Self: Search<MaybeUninit<T>, I>,
{
Search::get_mut(self).assume_init_drop()
}
#[cfg(feature = "uninit")]
#[cfg_attr(docsrs, doc(cfg(feature = "uninit")))]
fn uninit_as_ptr(&self) -> <Self::Initialized as TupleLike>::AsPtrOutput
where
Self: Uninit,
{
Uninit::as_ptr(self)
}
#[cfg(feature = "uninit")]
#[cfg_attr(docsrs, doc(cfg(feature = "uninit")))]
fn uninit_as_mut_ptr(&mut self) -> <Self::Initialized as TupleLike>::AsMutPtrOutput
where
Self: Uninit,
{
Uninit::as_mut_ptr(self)
}
#[cfg(feature = "uninit")]
#[cfg_attr(docsrs, doc(cfg(feature = "uninit")))]
fn uninit_write_one<T, I>(&mut self, value: T) -> &mut T
where
Self: Search<MaybeUninit<T>, I>,
{
Search::get_mut(self).write(value)
}
#[cfg(feature = "uninit")]
#[cfg_attr(docsrs, doc(cfg(feature = "uninit")))]
fn uninit_write(
&mut self,
init: Self::Initialized,
) -> <Self::Initialized as TupleLike>::AsMutOutput<'_>
where
Self: Uninit,
{
Uninit::write(self, init)
}
#[cfg(feature = "uninit")]
#[cfg_attr(docsrs, doc(cfg(feature = "uninit")))]
unsafe fn uninit_assume_init_subseq<Seq, I>(self) -> Self::PartiallyInitialized
where
Seq: TupleLike,
Self: UninitSubseq<Seq, I> + Sized,
{
UninitSubseq::assume_init_subseq(self)
}
#[cfg(feature = "uninit")]
#[cfg_attr(docsrs, doc(cfg(feature = "uninit")))]
unsafe fn uninit_assume_init_read_subseq<Seq, I>(&self) -> Seq
where
Seq: TupleLike,
Self: UninitSubseq<Seq, I>,
{
UninitSubseq::assume_init_read_subseq(self)
}
#[cfg(feature = "uninit")]
#[cfg_attr(docsrs, doc(cfg(feature = "uninit")))]
unsafe fn uninit_assume_init_ref_subseq<Seq, I>(&self) -> <Seq as TupleLike>::AsRefOutput<'_>
where
Seq: TupleLike,
Self: UninitSubseq<Seq, I>,
{
UninitSubseq::assume_init_ref_subseq(self)
}
#[cfg(feature = "uninit")]
#[cfg_attr(docsrs, doc(cfg(feature = "uninit")))]
unsafe fn uninit_assume_init_mut_subseq<Seq, I>(
&mut self,
) -> <Seq as TupleLike>::AsMutOutput<'_>
where
Seq: TupleLike,
Self: UninitSubseq<Seq, I>,
{
UninitSubseq::assume_init_mut_subseq(self)
}
#[cfg(feature = "uninit")]
#[cfg_attr(docsrs, doc(cfg(feature = "uninit")))]
fn uninit_subseq_as_ptr<Seq, I>(&self) -> <Seq as TupleLike>::AsPtrOutput
where
Seq: TupleLike,
Self: UninitSubseq<Seq, I>,
{
UninitSubseq::subseq_as_ptr(self)
}
#[cfg(feature = "uninit")]
#[cfg_attr(docsrs, doc(cfg(feature = "uninit")))]
fn uninit_subseq_as_mut_ptr<Seq, I>(&mut self) -> <Seq as TupleLike>::AsMutPtrOutput
where
Seq: TupleLike,
Self: UninitSubseq<Seq, I>,
{
UninitSubseq::subseq_as_mut_ptr(self)
}
#[cfg(feature = "uninit")]
#[cfg_attr(docsrs, doc(cfg(feature = "uninit")))]
fn uninit_write_subseq<Seq, I>(&mut self, subseq: Seq) -> Seq::AsMutOutput<'_>
where
Seq: TupleLike,
Self: UninitSubseq<Seq, I>,
{
UninitSubseq::write_subseq(self, subseq)
}
#[cfg(feature = "uninit")]
#[cfg_attr(docsrs, doc(cfg(feature = "uninit")))]
unsafe fn uninit_assume_init_drop_subseq<Seq, I>(&mut self)
where
Seq: TupleLike,
Self: UninitSubseq<Seq, I>,
{
UninitSubseq::assume_init_drop_subseq(self)
}
#[cfg(feature = "uninit")]
#[cfg_attr(docsrs, doc(cfg(feature = "uninit")))]
unsafe fn uninit_assume_init_con_subseq<Seq, I>(self) -> Self::PartiallyInitialized
where
Seq: TupleLike,
Self: UninitConSubseq<Seq, I> + Sized,
{
UninitConSubseq::assume_init_con_subseq(self)
}
#[cfg(feature = "uninit")]
#[cfg_attr(docsrs, doc(cfg(feature = "uninit")))]
unsafe fn uninit_assume_init_read_con_subseq<Seq, I>(&self) -> Seq
where
Seq: TupleLike,
Self: UninitConSubseq<Seq, I>,
{
UninitConSubseq::assume_init_read_con_subseq(self)
}
#[cfg(feature = "uninit")]
#[cfg_attr(docsrs, doc(cfg(feature = "uninit")))]
unsafe fn uninit_assume_init_ref_con_subseq<Seq, I>(
&self,
) -> <Seq as TupleLike>::AsRefOutput<'_>
where
Seq: TupleLike,
Self: UninitConSubseq<Seq, I>,
{
UninitConSubseq::assume_init_ref_con_subseq(self)
}
#[cfg(feature = "uninit")]
#[cfg_attr(docsrs, doc(cfg(feature = "uninit")))]
unsafe fn uninit_assume_init_mut_con_subseq<Seq, I>(
&mut self,
) -> <Seq as TupleLike>::AsMutOutput<'_>
where
Seq: TupleLike,
Self: UninitConSubseq<Seq, I>,
{
UninitConSubseq::assume_init_mut_con_subseq(self)
}
#[cfg(feature = "uninit")]
#[cfg_attr(docsrs, doc(cfg(feature = "uninit")))]
fn uninit_con_subseq_as_ptr<Seq, I>(&self) -> <Seq as TupleLike>::AsPtrOutput
where
Seq: TupleLike,
Self: UninitConSubseq<Seq, I>,
{
UninitConSubseq::con_subseq_as_ptr(self)
}
#[cfg(feature = "uninit")]
#[cfg_attr(docsrs, doc(cfg(feature = "uninit")))]
fn uninit_con_subseq_as_mut_ptr<Seq, I>(&mut self) -> <Seq as TupleLike>::AsMutPtrOutput
where
Seq: TupleLike,
Self: UninitConSubseq<Seq, I>,
{
UninitConSubseq::con_subseq_as_mut_ptr(self)
}
#[cfg(feature = "uninit")]
#[cfg_attr(docsrs, doc(cfg(feature = "uninit")))]
fn uninit_write_con_subseq<Seq, I>(&mut self, subseq: Seq) -> Seq::AsMutOutput<'_>
where
Seq: TupleLike,
Self: UninitConSubseq<Seq, I>,
{
UninitConSubseq::write_con_subseq(self, subseq)
}
#[cfg(feature = "uninit")]
#[cfg_attr(docsrs, doc(cfg(feature = "uninit")))]
unsafe fn uninit_assume_init_drop_con_subseq<Seq, I>(&mut self)
where
Seq: TupleLike,
Self: UninitConSubseq<Seq, I>,
{
UninitConSubseq::assume_init_drop_con_subseq(self)
}
fn untuple(self) -> Self::UntupleOutput
where
Self: Untupleable + Sized,
{
Untupleable::untuple(self)
}
fn flatten(self) -> Self::UntupleOutput
where
Self: Untupleable + Sized,
{
Untupleable::untuple(self)
}
fn foreach<F>(self, mapper: F) -> <Self as Foreach<F>>::Output
where
Self: Foreach<F> + Sized,
{
Foreach::foreach(self, mapper)
}
fn fold<F, Acc>(self, folder: F, acc: Acc) -> <Self as Foldable<F, Acc>>::Output
where
Self: Foldable<F, Acc> + Sized,
{
Foldable::fold(self, folder, acc)
}
fn any<Pred>(&self, predicate: Pred) -> bool
where
Self: TestAny<Pred>,
{
TestAny::any(self, predicate)
}
fn all<Pred>(&self, predicate: Pred) -> bool
where
Self: TestAll<Pred>,
{
TestAll::all(self, predicate)
}
fn dot<T>(self, rhs: T) -> <Self as Dot<T>>::Output
where
Self: Dot<T> + Sized,
{
Dot::dot(self, rhs)
}
fn zip<T>(self, rhs: T) -> Self::ZipOutput
where
Self: Zippable<T> + Sized,
{
Zippable::zip(self, rhs)
}
fn zip2<T>(self, rhs: T) -> Self::ZipOutput2
where
Self: Zippable<T> + Sized,
{
Zippable::zip2(self, rhs)
}
fn unzip(self) -> (Self::UnzipOutputLeft, Self::UnzipOutputRight)
where
Self: Unzippable + Sized,
{
Unzippable::unzip(self)
}
fn extend<T>(self, rhs: T) -> Self::ExtendBackOutput
where
Self: Extendable<T> + Sized,
{
Extendable::extend(self, rhs)
}
fn extend_front<T>(self, rhs: T) -> Self::ExtendFrontOutput
where
Self: Extendable<T> + Sized,
{
Extendable::extend_front(self, rhs)
}
fn extend_back<T>(self, rhs: T) -> Self::ExtendBackOutput
where
Self: Extendable<T> + Sized,
{
Extendable::extend_back(self, rhs)
}
fn shrink(self) -> (Self::ShrinkBackOutput, Self::ShrinkBackElements)
where
Self: Shrinkable + Sized,
{
Shrinkable::shrink(self)
}
fn shrink_front(self) -> (Self::ShrinkFrontOutput, Self::ShrinkFrontElements)
where
Self: Shrinkable + Sized,
{
Shrinkable::shrink_front(self)
}
fn shrink_back(self) -> (Self::ShrinkBackOutput, Self::ShrinkBackElements)
where
Self: Shrinkable + Sized,
{
Shrinkable::shrink_back(self)
}
fn combine<T>(self, rhs: T) -> Self::CombineOutput
where
Self: Combinable<T> + Sized,
{
Combinable::combine(self, rhs)
}
fn replace_head<T>(self, rhs: T) -> (Self::ReplaceOutput, Self::Replaced)
where
T: TupleLike,
Self: HeadReplaceable<T> + Sized,
{
HeadReplaceable::replace_head(self, rhs)
}
fn replace_tail<T, I>(self, rhs: T) -> (Self::ReplaceOutput, Self::Replaced)
where
T: TupleLike,
Self: TailReplaceable<T, I> + Sized,
{
TailReplaceable::replace_tail(self, rhs)
}
fn call<T, P>(&self, rhs: T) -> <Self as Callable<T, P>>::Output
where
Self: Callable<T, P>,
{
Callable::call(self, rhs)
}
fn call_mut<T, P>(&mut self, rhs: T) -> <Self as MutCallable<T, P>>::Output
where
Self: MutCallable<T, P>,
{
MutCallable::call_mut(self, rhs)
}
fn call_once<T, P>(self, rhs: T) -> <Self as OnceCallable<T, P>>::Output
where
Self: OnceCallable<T, P> + Sized,
{
OnceCallable::call_once(self, rhs)
}
#[cfg(feature = "unwrap")]
#[cfg_attr(docsrs, doc(cfg(feature = "unwrap")))]
fn unwrap(self) -> Self::UnwrapOutput
where
Self: Unwrap + Sized,
{
Unwrap::unwrap(self)
}
#[cfg(feature = "unwrap")]
#[cfg_attr(docsrs, doc(cfg(feature = "unwrap")))]
fn has_value(&self) -> bool
where
Self: Unwrap,
{
Unwrap::has_value(self)
}
#[cfg(feature = "unwrap")]
#[cfg_attr(docsrs, doc(cfg(feature = "unwrap")))]
fn unwrap_or_default(self) -> Self::UnwrapOutput
where
Self: UnwrapOrDefault + Sized,
{
UnwrapOrDefault::unwrap_or_default(self)
}
#[cfg(feature = "unwrap")]
#[cfg_attr(docsrs, doc(cfg(feature = "unwrap")))]
fn try_unwrap(self) -> Option<Self::UnwrapOutput>
where
Self: Unwrap + Sized,
{
if Unwrap::has_value(&self) {
Some(Unwrap::unwrap(self))
} else {
None
}
}
}
impl TupleLike for Unit {
type AsRefOutput<'a> = Unit;
type AsMutOutput<'a> = Unit;
type AsPtrOutput = Unit;
type AsMutPtrOutput = Unit;
type AsPinRefOutput<'a> = Unit;
type AsPinMutOutput<'a> = Unit;
type PushFrontOutput<T> = Tuple<T, Unit>;
type PushBackOutput<T> = Tuple<T, Unit>;
type RevOutput = Unit;
type JoinOutput<T>
= T
where
T: TupleLike;
type ToSomeOutput = Unit;
type ToOkOutput<E> = Unit;
type ToTupleOutput = Unit;
#[cfg(feature = "uninit")]
type Uninit = Unit;
const LEN: usize = 0;
fn as_ref(&self) -> Self::AsRefOutput<'_> {
Self
}
fn as_mut(&mut self) -> Self::AsMutOutput<'_> {
Self
}
fn as_ptr(&self) -> Self::AsPtrOutput {
Unit
}
fn as_mut_ptr(&mut self) -> Self::AsMutPtrOutput {
Unit
}
fn as_pin_ref(self: Pin<&Self>) -> Self::AsPinRefOutput<'_> {
Unit
}
fn as_pin_mut(self: Pin<&mut Self>) -> Self::AsPinMutOutput<'_> {
Unit
}
fn push<T>(self, value: T) -> Self::PushBackOutput<T> {
Tuple(value, self)
}
fn push_front<T>(self, value: T) -> Self::PushFrontOutput<T> {
Tuple(value, self)
}
fn push_back<T>(self, value: T) -> Self::PushBackOutput<T> {
Tuple(value, self)
}
fn rev(self) -> Self::RevOutput {
self
}
fn join<T>(self, value: T) -> Self::JoinOutput<T>
where
T: TupleLike,
{
value
}
fn to_some(self) -> Self::ToSomeOutput {
self
}
fn to_ok<E>(self) -> Self::ToOkOutput<E> {
self
}
fn to_tuple(self) -> Self::ToTupleOutput {
self
}
#[cfg(feature = "uninit")]
fn uninit() -> Self::Uninit {
Unit
}
#[cfg(feature = "uninit")]
fn zeroed() -> Self::Uninit {
Unit
}
#[cfg(feature = "uninit")]
fn to_uninit(self) -> Self::Uninit {
Unit
}
}
impl<First, Other> TupleLike for Tuple<First, Other>
where
Other: TupleLike,
{
type AsRefOutput<'a>
= Tuple<&'a First, Other::AsRefOutput<'a>>
where
Self: 'a;
type AsMutOutput<'a>
= Tuple<&'a mut First, Other::AsMutOutput<'a>>
where
Self: 'a;
type AsPtrOutput = Tuple<*const First, Other::AsPtrOutput>;
type AsMutPtrOutput = Tuple<*mut First, Other::AsMutPtrOutput>;
type AsPinRefOutput<'a>
= Tuple<Pin<&'a First>, Other::AsPinRefOutput<'a>>
where
Self: 'a;
type AsPinMutOutput<'a>
= Tuple<Pin<&'a mut First>, Other::AsPinMutOutput<'a>>
where
Self: 'a;
type PushFrontOutput<T> = Tuple<T, Self>;
type PushBackOutput<T> = Tuple<First, Other::PushBackOutput<T>>;
type RevOutput = <Other::RevOutput as TupleLike>::PushBackOutput<First>;
type JoinOutput<T>
= Tuple<First, Other::JoinOutput<T>>
where
T: TupleLike;
type ToSomeOutput = Tuple<Option<First>, Other::ToSomeOutput>;
type ToOkOutput<E> = Tuple<Result<First, E>, Other::ToOkOutput<E>>;
type ToTupleOutput = Tuple<Tuple<First, Unit>, Other::ToTupleOutput>;
#[cfg(feature = "uninit")]
type Uninit = Tuple<MaybeUninit<First>, Other::Uninit>;
const LEN: usize = Other::LEN + 1;
fn as_ref(&self) -> Self::AsRefOutput<'_> {
Tuple(&self.0, self.1.as_ref())
}
fn as_mut(&mut self) -> Self::AsMutOutput<'_> {
Tuple(&mut self.0, self.1.as_mut())
}
fn as_ptr(&self) -> Self::AsPtrOutput {
Tuple(&self.0, self.1.as_ptr())
}
fn as_mut_ptr(&mut self) -> Self::AsMutPtrOutput {
Tuple(&mut self.0, self.1.as_mut_ptr())
}
fn as_pin_ref(self: Pin<&Self>) -> Self::AsPinRefOutput<'_> {
let this = Pin::get_ref(self);
unsafe {
Tuple(
Pin::new_unchecked(&this.0),
Pin::new_unchecked(&this.1).as_pin_ref(),
)
}
}
fn as_pin_mut(self: Pin<&mut Self>) -> Self::AsPinMutOutput<'_> {
unsafe {
let this = Pin::get_unchecked_mut(self);
Tuple(
Pin::new_unchecked(&mut this.0),
Pin::new_unchecked(&mut this.1).as_pin_mut(),
)
}
}
fn push<T>(self, value: T) -> Self::PushBackOutput<T> {
Tuple(self.0, self.1.push(value))
}
fn push_front<T>(self, value: T) -> Self::PushFrontOutput<T> {
Tuple(value, self)
}
fn push_back<T>(self, value: T) -> Self::PushBackOutput<T> {
self.push::<T>(value)
}
fn rev(self) -> Self::RevOutput {
self.1.rev().push(self.0)
}
fn join<T>(self, value: T) -> Self::JoinOutput<T>
where
T: TupleLike,
{
Tuple(self.0, self.1.join(value))
}
fn to_some(self) -> Self::ToSomeOutput {
Tuple(Some(self.0), self.1.to_some())
}
fn to_ok<E>(self) -> Self::ToOkOutput<E> {
Tuple(Ok(self.0), self.1.to_ok())
}
fn to_tuple(self) -> Self::ToTupleOutput {
Tuple(Tuple(self.0, Unit), self.1.to_tuple())
}
#[cfg(feature = "uninit")]
fn uninit() -> Self::Uninit {
Tuple(MaybeUninit::uninit(), Other::uninit())
}
#[cfg(feature = "uninit")]
fn zeroed() -> Self::Uninit {
Tuple(MaybeUninit::zeroed(), Other::zeroed())
}
#[cfg(feature = "uninit")]
fn to_uninit(self) -> Self::Uninit {
Tuple(MaybeUninit::new(self.0), TupleLike::to_uninit(self.1))
}
}
pub trait TupleLenEqTo<T: TupleLike>: TupleLike {}
impl TupleLenEqTo<Unit> for Unit {}
impl<First1, Other1, First2, Other2> TupleLenEqTo<Tuple<First2, Other2>> for Tuple<First1, Other1>
where
Other1: TupleLenEqTo<Other2>,
Other2: TupleLike,
{
}
pub trait ToPrimitive {
type Primitive;
fn primitive(self) -> Self::Primitive;
}
pub trait ToArray<T>: TupleLike {
type Array: IntoIterator<Item = T>;
type Iter<'a>: Iterator<Item = &'a T>
where
Self::AsRefOutput<'a>: ToArray<&'a T>,
Self: 'a,
T: 'a;
type IterMut<'a>: Iterator<Item = &'a mut T>
where
Self::AsMutOutput<'a>: ToArray<&'a mut T>,
Self: 'a,
T: 'a;
fn to_array(self) -> Self::Array;
fn iter<'a>(&'a self) -> Self::Iter<'a>
where
Self::AsRefOutput<'a>: ToArray<&'a T>,
Self: 'a,
T: 'a;
fn iter_mut<'a>(&'a mut self) -> Self::IterMut<'a>
where
Self::AsMutOutput<'a>: ToArray<&'a mut T>,
Self: 'a,
T: 'a;
}
tuple_traits_impl!(32);
__tuple_unary_ops_impl! {
Neg::neg(),
Not::not(),
}
__tuple_binary_ops_impl! {
Add::add(),
Sub::sub(),
Mul::mul(),
Div::div(),
Rem::rem(),
BitAnd::bitand(),
BitOr::bitor(),
BitXor::bitxor(),
Shl::shl(),
Shr::shr(),
}
__tuple_assignment_ops_impl! {
AddAssign::add_assign(),
SubAssign::sub_assign(),
MulAssign::mul_assign(),
DivAssign::div_assign(),
RemAssign::rem_assign(),
BitAndAssign::bitand_assign(),
BitOrAssign::bitor_assign(),
BitXorAssign::bitxor_assign(),
ShlAssign::shl_assign(),
ShrAssign::shr_assign(),
}
impl<T, Other> IntoIterator for Tuple<T, Other>
where
Tuple<T, Other>: ToArray<T>,
{
type Item = T;
type IntoIter = <<Self as ToArray<T>>::Array as IntoIterator>::IntoIter;
fn into_iter(self) -> Self::IntoIter {
self.to_array().into_iter()
}
}
impl<'a, T, Other> IntoIterator for &'a Tuple<T, Other>
where
Tuple<T, Other>: TupleLike,
<Tuple<T, Other> as TupleLike>::AsRefOutput<'a>: ToArray<&'a T>,
{
type Item = &'a T;
type IntoIter = <<<Tuple<T, Other> as TupleLike>::AsRefOutput<'a> as ToArray<&'a T>>::Array as IntoIterator>::IntoIter;
fn into_iter(self) -> Self::IntoIter {
self.as_ref().to_array().into_iter()
}
}
impl<'a, T, Other> IntoIterator for &'a mut Tuple<T, Other>
where
Tuple<T, Other>: TupleLike,
<Tuple<T, Other> as TupleLike>::AsMutOutput<'a>: ToArray<&'a mut T>,
{
type Item = &'a mut T;
type IntoIter = <<<Tuple<T, Other> as TupleLike>::AsMutOutput<'a> as ToArray<&'a mut T>>::Array as IntoIterator>::IntoIter;
fn into_iter(self) -> Self::IntoIter {
self.as_mut().to_array().into_iter()
}
}