Trait tuplez::TupleLike

source ·
pub trait TupleLike {
Show 127 associated items 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; type Uninit: TupleLike; const LEN: usize; // Required methods 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 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 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; fn uninit() -> Self::Uninit; fn zeroed() -> Self::Uninit; fn to_uninit(self) -> Self::Uninit; // Provided methods fn len(&self) -> usize { ... } fn is_empty(&self) -> bool { ... } fn by_ref(&mut self) -> &mut Self where Self: Sized { ... } fn enumerate(self) -> Self::EnumerateOutput where Self: Sized + Enumerable { ... } fn take<T, I>(self) -> (T, Self::TakeRemainder) where Self: Search<T, I> + Sized { ... } fn get_ref<T, I>(&self) -> &T where Self: Search<T, I> + Sized { ... } fn get_mut<T, I>(&mut self) -> &mut T where Self: Search<T, I> + Sized { ... } fn swap<T, I>(&mut self, value: &mut T) where Self: Search<T, I> { ... } fn replace<T, I>(&mut self, value: T) -> T where Self: Search<T, I> { ... } fn map_replace<T, U, F, I>(self, f: F) -> Self::MapReplaceOutput<U> where Self: Search<T, I> + Sized, F: FnOnce(T) -> U { ... } fn subseq<Seq, I>(self) -> Seq where Self: Subseq<Seq, I> + Sized, Seq: TupleLike { ... } fn subseq_ref<Seq, I>(&self) -> Seq::AsRefOutput<'_> where Self: Subseq<Seq, I> + Sized, Seq: TupleLike { ... } fn subseq_mut<Seq, I>(&mut self) -> Seq::AsMutOutput<'_> where Self: Subseq<Seq, I> + Sized, Seq: TupleLike { ... } fn swap_subseq<Seq, I>(&mut self, subseq: &mut Seq) where Seq: TupleLike, Self: Subseq<Seq, I> { ... } fn replace_subseq<Seq, I>(&mut self, subseq: Seq) -> Seq where Seq: TupleLike, Self: Subseq<Seq, I> { ... } fn map_replace_subseq<Seq, F, I>(self, f: F) -> Self::MapReplaceOutput where Seq: TupleLike, Self: SubseqMapReplace<Seq, F, I> + Sized { ... } fn foreach_subseq<Seq, F, I>(self, f: F) -> Self::MapReplaceOutput where Seq: TupleLike, Self: SubseqMapReplace<Seq, F, I> + Sized { ... } fn con_subseq<Seq, I>(self) -> Seq where Seq: TupleLike, Self: ConSubseq<Seq, I> + Sized { ... } fn con_subseq_ref<Seq, I>(&self) -> Seq::AsRefOutput<'_> where Seq: TupleLike, Self: ConSubseq<Seq, I> { ... } fn con_subseq_mut<Seq, I>(&mut self) -> Seq::AsMutOutput<'_> where Seq: TupleLike, Self: ConSubseq<Seq, I> { ... } fn swap_con_subseq<Seq, I>(&mut self, subseq: &mut Seq) where Seq: TupleLike, Self: ConSubseq<Seq, I> { ... } fn replace_con_subseq<Seq, I>(&mut self, subseq: Seq) -> Seq where Seq: TupleLike, Self: ConSubseq<Seq, I> { ... } fn map_replace_con_subseq<Seq, F, I>(self, f: F) -> Self::MapReplaceOutput where Seq: TupleLike, Self: ConSubseqMapReplace<Seq, F, I> + Sized { ... } fn foreach_con_subseq<Seq, F, I>(self, f: F) -> Self::MapReplaceOutput where Seq: TupleLike, Self: ConSubseqMapReplace<Seq, F, I> + Sized { ... } fn subset<Seq, I>(self) -> Seq where Self: Subseq<Seq, I> + Sized, Seq: TupleLike { ... } fn subset_ref<Seq, I>(&self) -> Seq::AsRefOutput<'_> where Self: Subseq<Seq, I> + Sized, Seq: TupleLike { ... } fn subset_mut<Seq, I>(&mut self) -> Seq::AsMutOutput<'_> where Self: Subseq<Seq, I> + Sized, Seq: TupleLike { ... } fn swap_with<Seq, I>(&mut self, subseq: &mut Seq) where Seq: TupleLike, Self: ConSubseq<Seq, I> { ... } fn replace_with<Seq, I>(&mut self, subseq: Seq) -> Seq where Seq: TupleLike, Self: ConSubseq<Seq, I> { ... } fn as_deref(&self) -> Self::AsDerefOutput<'_> where Self: AsDeref { ... } fn as_deref_mut(&mut self) -> Self::AsDerefMutOutput<'_> where Self: AsDerefMut { ... } fn cloned(&self) -> Self::ClonedOutput where Self: Cloned { ... } fn copied(&self) -> Self::CopiedOutput where Self: Copied { ... } fn owned(&self) -> Self::OwnedOutput where Self: Owned { ... } fn pop(self) -> (Self::PopBackOutput, Self::PopBackElement) where Self: Poppable + Sized { ... } fn pop_front(self) -> (Self::PopFrontOutput, Self::PopFrontElement) where Self: Poppable + Sized { ... } fn pop_back(self) -> (Self::PopBackOutput, Self::PopBackElement) where Self: Poppable + Sized { ... } fn rot_l(self) -> Self::RotLeftOutput where Self: Rotatable + Sized { ... } fn rot_r(self) -> Self::RotRightOutput where Self: Rotatable + Sized { ... } unsafe fn uninit_assume_init(self) -> Self::Initialized where Self: Uninit + Sized { ... } unsafe fn uninit_assume_init_one<T, I>(self) -> Self::MapReplaceOutput<T> where Self: Search<MaybeUninit<T>, I> + Sized { ... } unsafe fn uninit_assume_init_read(&self) -> Self::Initialized where Self: Uninit { ... } unsafe fn uninit_assume_init_read_one<T, I>(&self) -> T where Self: Search<MaybeUninit<T>, I> { ... } unsafe fn uninit_assume_init_ref( &self, ) -> <Self::Initialized as TupleLike>::AsRefOutput<'_> where Self: Uninit { ... } unsafe fn uninit_assume_init_ref_one<T, I>(&self) -> &T where Self: Search<MaybeUninit<T>, I> { ... } unsafe fn uninit_assume_init_mut( &mut self, ) -> <Self::Initialized as TupleLike>::AsMutOutput<'_> where Self: Uninit { ... } unsafe fn uninit_assume_init_mut_one<T, I>(&mut self) -> &mut T where Self: Search<MaybeUninit<T>, I> { ... } unsafe fn uninit_assume_init_drop(&mut self) where Self: Uninit { ... } unsafe fn uninit_assume_init_drop_one<T, I>(&mut self) where Self: Search<MaybeUninit<T>, I> { ... } fn uninit_as_ptr(&self) -> <Self::Initialized as TupleLike>::AsPtrOutput where Self: Uninit { ... } fn uninit_as_mut_ptr( &mut self, ) -> <Self::Initialized as TupleLike>::AsMutPtrOutput where Self: Uninit { ... } fn uninit_write_one<T, I>(&mut self, value: T) -> &mut T where Self: Search<MaybeUninit<T>, I> { ... } fn uninit_write( &mut self, init: Self::Initialized, ) -> <Self::Initialized as TupleLike>::AsMutOutput<'_> where Self: Uninit { ... } unsafe fn uninit_assume_init_subseq<Seq, I>( self, ) -> Self::PartiallyInitialized where Seq: TupleLike, Self: UninitSubseq<Seq, I> + Sized { ... } unsafe fn uninit_assume_init_read_subseq<Seq, I>(&self) -> Seq where Seq: TupleLike, Self: UninitSubseq<Seq, I> { ... } unsafe fn uninit_assume_init_ref_subseq<Seq, I>( &self, ) -> <Seq as TupleLike>::AsRefOutput<'_> where Seq: TupleLike, Self: UninitSubseq<Seq, I> { ... } unsafe fn uninit_assume_init_mut_subseq<Seq, I>( &mut self, ) -> <Seq as TupleLike>::AsMutOutput<'_> where Seq: TupleLike, Self: UninitSubseq<Seq, I> { ... } fn uninit_subseq_as_ptr<Seq, I>(&self) -> <Seq as TupleLike>::AsPtrOutput where Seq: TupleLike, Self: UninitSubseq<Seq, I> { ... } fn uninit_subseq_as_mut_ptr<Seq, I>( &mut self, ) -> <Seq as TupleLike>::AsMutPtrOutput where Seq: TupleLike, Self: UninitSubseq<Seq, I> { ... } fn uninit_write_subseq<Seq, I>( &mut self, subseq: Seq, ) -> Seq::AsMutOutput<'_> where Seq: TupleLike, Self: UninitSubseq<Seq, I> { ... } unsafe fn uninit_assume_init_drop_subseq<Seq, I>(&mut self) where Seq: TupleLike, Self: UninitSubseq<Seq, I> { ... } unsafe fn uninit_assume_init_con_subseq<Seq, I>( self, ) -> Self::PartiallyInitialized where Seq: TupleLike, Self: UninitConSubseq<Seq, I> + Sized { ... } unsafe fn uninit_assume_init_read_con_subseq<Seq, I>(&self) -> Seq where Seq: TupleLike, Self: UninitConSubseq<Seq, I> { ... } unsafe fn uninit_assume_init_ref_con_subseq<Seq, I>( &self, ) -> <Seq as TupleLike>::AsRefOutput<'_> where Seq: TupleLike, Self: UninitConSubseq<Seq, I> { ... } unsafe fn uninit_assume_init_mut_con_subseq<Seq, I>( &mut self, ) -> <Seq as TupleLike>::AsMutOutput<'_> where Seq: TupleLike, Self: UninitConSubseq<Seq, I> { ... } fn uninit_con_subseq_as_ptr<Seq, I>( &self, ) -> <Seq as TupleLike>::AsPtrOutput where Seq: TupleLike, Self: UninitConSubseq<Seq, I> { ... } fn uninit_con_subseq_as_mut_ptr<Seq, I>( &mut self, ) -> <Seq as TupleLike>::AsMutPtrOutput where Seq: TupleLike, Self: UninitConSubseq<Seq, I> { ... } fn uninit_write_con_subseq<Seq, I>( &mut self, subseq: Seq, ) -> Seq::AsMutOutput<'_> where Seq: TupleLike, Self: UninitConSubseq<Seq, I> { ... } unsafe fn uninit_assume_init_drop_con_subseq<Seq, I>(&mut self) where Seq: TupleLike, Self: UninitConSubseq<Seq, I> { ... } fn untuple(self) -> Self::UntupleOutput where Self: Untupleable + Sized { ... } fn flatten(self) -> Self::UntupleOutput where Self: Untupleable + Sized { ... } fn foreach<F>(self, mapper: F) -> <Self as Foreach<F>>::Output where Self: Foreach<F> + Sized { ... } fn fold<F, Acc>( self, folder: F, acc: Acc, ) -> <Self as Foldable<F, Acc>>::Output where Self: Foldable<F, Acc> + Sized { ... } fn any<Pred>(&self, predicate: Pred) -> bool where Self: TestAny<Pred> { ... } fn all<Pred>(&self, predicate: Pred) -> bool where Self: TestAll<Pred> { ... } fn dot<T>(self, rhs: T) -> <Self as Dot<T>>::Output where Self: Dot<T> + Sized { ... } fn zip<T>(self, rhs: T) -> Self::ZipOutput where Self: Zippable<T> + Sized { ... } fn zip2<T>(self, rhs: T) -> Self::ZipOutput2 where Self: Zippable<T> + Sized { ... } fn unzip(self) -> (Self::UnzipOutputLeft, Self::UnzipOutputRight) where Self: Unzippable + Sized { ... } fn extend<T>(self, rhs: T) -> Self::ExtendBackOutput where Self: Extendable<T> + Sized { ... } fn extend_front<T>(self, rhs: T) -> Self::ExtendFrontOutput where Self: Extendable<T> + Sized { ... } fn extend_back<T>(self, rhs: T) -> Self::ExtendBackOutput where Self: Extendable<T> + Sized { ... } fn shrink(self) -> (Self::ShrinkBackOutput, Self::ShrinkBackElements) where Self: Shrinkable + Sized { ... } fn shrink_front( self, ) -> (Self::ShrinkFrontOutput, Self::ShrinkFrontElements) where Self: Shrinkable + Sized { ... } fn shrink_back(self) -> (Self::ShrinkBackOutput, Self::ShrinkBackElements) where Self: Shrinkable + Sized { ... } fn combine<T>(self, rhs: T) -> Self::CombineOutput where Self: Combinable<T> + Sized { ... } fn replace_head<T>(self, rhs: T) -> (Self::ReplaceOutput, Self::Replaced) where T: TupleLike, Self: HeadReplaceable<T> + Sized { ... } fn replace_tail<T, I>(self, rhs: T) -> (Self::ReplaceOutput, Self::Replaced) where T: TupleLike, Self: TailReplaceable<T, I> + Sized { ... } fn call<T, P>(&self, rhs: T) -> <Self as Callable<T, P>>::Output where Self: Callable<T, P> { ... } fn call_mut<T, P>(&mut self, rhs: T) -> <Self as MutCallable<T, P>>::Output where Self: MutCallable<T, P> { ... } fn call_once<T, P>(self, rhs: T) -> <Self as OnceCallable<T, P>>::Output where Self: OnceCallable<T, P> + Sized { ... } fn unwrap(self) -> Self::UnwrapOutput where Self: Unwrap + Sized { ... } fn has_value(&self) -> bool where Self: Unwrap { ... } fn unwrap_or_default(self) -> Self::UnwrapOutput where Self: UnwrapOrDefault + Sized { ... } fn try_unwrap(self) -> Option<Self::UnwrapOutput> where Self: Unwrap + Sized { ... }
}
Expand description

Define the basic methods of tuples.

NOTE: Due to the limitation that Rust does not support the variadic to represent primitive tuple types containing any number of elements, we cannot make TupleLike trait contain a method that converts tuple to the primitive tuple type. Therefore, this method is provided by the trait ToPrimitive and is only implemented for tuples with no more than 32 elements.

Required Associated Types§

source

type AsRefOutput<'a>: TupleLike where Self: 'a

The type of tuple containing immutable references to all elements of the tuple.

source

type AsMutOutput<'a>: TupleLike where Self: 'a

The type of tuple containing mutable references to all elements of the tuple.

source

type AsPtrOutput: TupleLike

The type of tuple containing pointers to all elements of the tuple.

source

type AsMutPtrOutput: TupleLike

The type of tuple containing mutable pointers to all elements of the tuple.

source

type AsPinRefOutput<'a>: TupleLike where Self: 'a

The type of tuple containing Pins of immutable references to all elements of the tuple.

source

type AsPinMutOutput<'a>: TupleLike where Self: 'a

The type of tuple containing Pins of mutable references to all elements of the tuple.

source

type PushFrontOutput<T>: TupleLike

The type of tuple generated by pushing an element to the front of the tuple.

source

type PushBackOutput<T>: TupleLike

The type of tuple generated by pushing an element to the back of the tuple.

source

type RevOutput: TupleLike

The type of tuple generated by reversing the tuple.

source

type JoinOutput<T>: TupleLike where T: TupleLike

The type of tuple generated by joining two tuples.

source

type ToSomeOutput: TupleLike

The type of tuple after wrapping all elements into Option.

source

type ToOkOutput<E>: TupleLike

The type of tuple after wrapping all elements into Result.

source

type ToTupleOutput: TupleLike

The type of tuple after wrapping all elements into Tuple.

source

type Uninit: TupleLike

Available on crate feature uninit only.

The type of tuple after wrapping all elements into MaybeUninit.

Required Associated Constants§

source

const LEN: usize

The number of elements in the tuple.

Required Methods§

source

fn as_ref(&self) -> Self::AsRefOutput<'_>

Generate a tuple containing immutable references to all elements of the tuple.

§Example
use tuplez::{tuple, TupleLike, tuple_t};

let tup = tuple!([1, 2], "hello".to_string());
let tup_ref: tuple_t!(&[i32; 2], &String) = tup.as_ref();
assert_eq!(tup_ref, tuple!(&[1, 2], &String::from("hello")));
source

fn as_mut(&mut self) -> Self::AsMutOutput<'_>

Generate a tuple containing mutable reference to all elements of the tuple.

§Example
use tuplez::{get, tuple, TupleLike};

let mut tup = tuple!(1, "hello");
let tup_mut = tup.as_mut();
*get!(tup_mut; 0) += 1;
*get!(tup_mut; 1) = "world";
assert_eq!(tup, tuple!(2, "world"));
source

fn as_ptr(&self) -> Self::AsPtrOutput

Generate a tuple containing pointers to all elements of the tuple.

§Example
use tuplez::{get, tuple, TupleLike};

let tup = tuple!(1, 3.14, "hello", vec![1, 2, 3]);
let tup_ptr = tup.as_ptr();
let pi = unsafe { &*get!(tup_ptr; 1) };
assert_eq!(pi, &3.14);
source

fn as_mut_ptr(&mut self) -> Self::AsMutPtrOutput

Generate a tuple containing mutable pointers to all elements of the tuple.

§Example
use tuplez::{get, tuple, TupleLike};

let mut tup = tuple!(1, 3.14, "hello", vec![1, 2, 3]);
let tup_ptr = tup.as_mut_ptr();
let v = unsafe { &mut *get!(tup_ptr; 3) };
v.push(4);
assert_eq!(v.len(), 4);
source

fn as_pin_ref(self: Pin<&Self>) -> Self::AsPinRefOutput<'_>

Convert from Pin<&Tuple<T0, T1, T2, ..> to Tuple<Pin<&T0>, Pin<&T1>, Pin<&T2>, ...>.

source

fn as_pin_mut(self: Pin<&mut Self>) -> Self::AsPinMutOutput<'_>

Convert from Pin<&mut Tuple<T0, T1, T2, ..> to Tuple<Pin<&mut T0>, Pin<&mut T1>, Pin<&mut T2>, ...>.

source

fn push<T>(self, value: T) -> Self::PushBackOutput<T>

Push an element to the back of the tuple.

§Examples
use tuplez::{tuple, TupleLike};

let tup = tuple!(1, "hello", 3.14);
let tup2 = tup.push(44);
assert_eq!(tup2, tuple!(1, "hello", 3.14, 44));
source

fn push_front<T>(self, value: T) -> Self::PushFrontOutput<T>

Push an element to the front of the tuple.

§Examples
use tuplez::{tuple, TupleLike};

let tup = tuple!(1, "hello", 3.14);
let tup2 = tup.push_front(44);
assert_eq!(tup2, tuple!(44, 1, "hello", 3.14));
source

fn push_back<T>(self, value: T) -> Self::PushBackOutput<T>

Push an element to the back of the tuple. Same as push().

source

fn rev(self) -> Self::RevOutput

Reverse elements of the tuple.

§Examples
use tuplez::{tuple, TupleLike};

let tup = tuple!(1, "hello", 3.14);
let tup2 = tup.rev();
assert_eq!(tup2, tuple!(3.14, "hello", 1));
source

fn join<T>(self, value: T) -> Self::JoinOutput<T>
where T: TupleLike,

Join two tuples.

§Examples
use tuplez::{tuple, TupleLike};

let tup = tuple!(1, "hello", 3.14);
let tup2 = tuple!(44, "world");
let tup3 = tup.join(tup2);
assert_eq!(tup3, tuple!(1, "hello", 3.14, 44, "world"));
source

fn to_some(self) -> Self::ToSomeOutput

Convert from tuple!(a, b, c ...) to tuple!(Some(a), Some(b), Some(c) ...).

See unwrap(), unwrap_or_default() or try_unwrap() for the opposite operation.

§Example
use tuplez::{tuple, TupleLike};

let tup = tuple!(1, "hello", 3.14);
assert_eq!(tup.to_some(), tuple!(Some(1), Some("hello"), Some(3.14)));
source

fn to_ok<E>(self) -> Self::ToOkOutput<E>

Convert from tuple!(a, b, c ...) to tuple!(Ok(a), Ok(b), Ok(c) ...).

Note: You need to provide the error type.

See unwrap(), unwrap_or_default() or try_unwrap() for the opposite operation.

§Example
use tuplez::{tuple, TupleLike};

let tup = tuple!(1, "hello", 3.14);
assert_eq!(tup.to_ok::<()>(), tuple!(Ok(1), Ok("hello"), Ok(3.14)));
source

fn to_tuple(self) -> Self::ToTupleOutput

Convert from tuple!(a, b, c ...) to tuple!(tuple!(a), tuple!(b), tuple!(c) ...).

See untuple() for the opposite operation.

§Example
use tuplez::{tuple, TupleLike};

let tup = tuple!(1, "hello", 3.14);
assert_eq!(tup.to_tuple(), tuple!(tuple!(1), tuple!("hello"), tuple!(3.14)));
source

fn uninit() -> Self::Uninit

Available on crate feature uninit only.

Create a new tuple that all elements are wrapped by MaybeUninit and in uninitialized states.

Similar to MaybeUninit::uninit(), dropping a tuple with uninitialized elements will never call elements’ drop codes. It is your responsibility to make sure elements get dropped if they got initialized.

§Example
use std::mem::MaybeUninit;
use tuplez::{TupleLike, tuple_t};

let uninit = <tuple_t!(i32, &str, Vec<String>)>::uninit();
let _: tuple_t!(MaybeUninit<i32>, MaybeUninit<&str>, MaybeUninit<Vec<String>>) = uninit;
source

fn zeroed() -> Self::Uninit

Available on crate feature uninit only.

Create a new tuple that all elements are wrapped by MaybeUninit and in uninitialized states, with the memory being filled with 0 bytes.

Similar to MaybeUninit::zeroed(), dropping a tuple with uninitialized elements will never call elements’ drop codes. It is your responsibility to make sure elements get dropped if they got initialized.

use std::mem::MaybeUninit;
use tuplez::{tuple, TupleLike, tuple_t};

let uninit = <tuple_t!(i32, bool, *const u8)>::zeroed();
let tup = unsafe { uninit.uninit_assume_init() };
assert_eq!(tup, tuple!(0, false, std::ptr::null()));
source

fn to_uninit(self) -> Self::Uninit

Available on crate feature uninit only.

Convert from tuple!(a, b, c ...) to tuple!(MaybeUninit::new(a), MaybeUninit::new(b), MaybeUninit::new(c) ...).

See uninit_assume_init() for the opposite operation.

§Example
use tuplez::{tuple, TupleLike};

let uninit = tuple!(1, "hello", 3.14).to_uninit();
let tup = unsafe { uninit.uninit_assume_init() };
assert_eq!(tup, tuple!(1, "hello", 3.14));

Provided Methods§

source

fn len(&self) -> usize

Get the number of elements in the tuple. MUST always return LEN.

§Example
use tuplez::{tuple, TupleLike};
assert_eq!(tuple!(1, "hello", 3.14).len(), 3);
source

fn is_empty(&self) -> bool

Check if tuple is empty.

Always be false if tuple is Unit, and always be true if tuple is Tuple.

§Example
use tuplez::{tuple, TupleLike};

assert_eq!(tuple!().is_empty(), true);
assert_eq!(tuple!(1, "hello", 3.14).is_empty(), false);
source

fn by_ref(&mut self) -> &mut Self
where Self: Sized,

Creates a “by reference” adapter for this instance.

It will simply borrow this current tuple.

source

fn enumerate(self) -> Self::EnumerateOutput
where Self: Sized + Enumerable,

Convert from tuple!(x, y, z, ...) to tuple!((0, x), (1, y), (2, z), ...).

§Example
use tuplez::{tuple, TupleLike};
 
let tup = tuple!("hello", Some([1, 2, 3]), tuple!(3.14, 12));
assert_eq!(tup.enumerate(), tuple!(
    (0, "hello"),
    (1, Some([1, 2, 3])),
    (2, tuple!(3.14, 12)),
));
source

fn take<T, I>(self) -> (T, Self::TakeRemainder)
where Self: Search<T, I> + Sized,

Take out the searched element, and get the remainder of tuple.

Add a type annotation to the searched element to let take() know which one you want.

NOTE: The type of this element must exist only once in the tuple.

If you want to take out the element at a specific index, see take!.

If you want to take out the first or last element, see pop().

§Example
use tuplez::{tuple, TupleLike};

let tup = tuple!(3.14, "hello", 5, [1, 2, 3]);
let (value, remainder): (i32, _) = tup.take();      // Add type annotation for `value`
assert_eq!(value, 5);
assert_eq!(remainder, tuple!(3.14, "hello", [1, 2, 3]));

If you cannot add a type annotation, you can also use the take! macro:

use tuplez::{take, tuple};

let tup = tuple!(3.14, "hello", 5, [1, 2, 3]);
let (value, remainder) = take!(tup; i32);
assert_eq!(value, 5);
assert_eq!(remainder, tuple!(3.14, "hello", [1, 2, 3]));
source

fn get_ref<T, I>(&self) -> &T
where Self: Search<T, I> + Sized,

Get an immutable reference of the searched element.

Add a type annotation to the searched element to let get_ref() know which one you want.

NOTE: The type of this element must exist only once in the tuple.

If you want to get the element by its index, see get!;

§Example
use tuplez::{tuple, TupleLike};

let tup = tuple!(3.14, "hello", 5, [1, 2, 3]);
let arr: &[i32; 3] = tup.get_ref();
assert_eq!(arr, &[1, 2, 3]);
source

fn get_mut<T, I>(&mut self) -> &mut T
where Self: Search<T, I> + Sized,

Get a mutable reference of the searched element.

Add a type annotation to the searched element to let get_mut() know which one you want.

NOTE: The type of this element must exist only once in the tuple.

If you want to get the element by its index, see get!;

§Example
use tuplez::{tuple, TupleLike};

let mut tup = tuple!(3.14, "hello", 5, [1, 2, 3]);
let s: &mut &str = tup.get_mut();
*s = "world";
assert_eq!(tup, tuple!(3.14, "world", 5, [1, 2, 3]));
source

fn swap<T, I>(&mut self, value: &mut T)
where Self: Search<T, I>,

Swap a specific element of the same type with another value.

NOTE: The type of this element must exist only once in the tuple.

§Example
use tuplez::{tuple, TupleLike};

let mut tup = tuple!(3.14, "hello", 5, [1, 2, 3]);
let mut s = "world";
tup.swap(&mut s);
assert_eq!(tup, tuple!(3.14, "world", 5, [1, 2, 3]));
assert_eq!(s, "hello");
source

fn replace<T, I>(&mut self, value: T) -> T
where Self: Search<T, I>,

Replace a specific element of the same type with another value.

Return the replaced value.

NOTE: The type of this element must exist only once in the tuple.

Hint: If you don’t want to consume the input tuple, then what you are looking for might be swap().

§Example
use tuplez::{tuple, TupleLike};

let mut tup = tuple!(3.14, "hello", 5, [1, 2, 3]);
let s = tup.replace("world");
assert_eq!(tup, tuple!(3.14, "world", 5, [1, 2, 3]));
assert_eq!(s, "hello");
source

fn map_replace<T, U, F, I>(self, f: F) -> Self::MapReplaceOutput<U>
where Self: Search<T, I> + Sized, F: FnOnce(T) -> U,

Replace a specific element with another value that may be of a different type.

The new element is generated a the user-defined function.

§Example
use tuplez::{tuple, TupleLike};

let tup = tuple!(1, 3.14, "hello", Some([1, 2, 3]));
let result = tup.map_replace(|x: f64| x.to_string());
assert_eq!(result, tuple!(1, "3.14".to_string(), "hello", Some([1, 2, 3])))
source

fn subseq<Seq, I>(self) -> Seq
where Self: Subseq<Seq, I> + Sized, Seq: TupleLike,

Take out a subsequence.

NOTE: The subsequence must have one and only one candidate in the supersequence.

Add a type annotation to the subsequence to let subseq() know.

§Example
use tuplez::{tuple, TupleLike, tuple_t};

let tup = tuple!(12, "hello", 24, 3.14, true);
let subseq: tuple_t!(&str, bool) = tup.subseq();
assert_eq!(subseq, tuple!("hello", true));

// Two candidates available: `(12, true)` or `(24, true)`.
// let subseq: tuple_t!(i32, bool) = tup.subseq();

// No candidates available.
// `(true, "hello")` cannot be a candidate, since its element order is
// different from the supersequence.
// let subseq: tuple_t!(bool, &str) = tup.subseq();

// Although `24` is also `i32`, but only `(12, "hello")` is a candidate.
let subseq: tuple_t!(i32, &str) = tup.subseq();
assert_eq!(subseq, tuple!(12, "hello"));

// It's OK to pick all `i32`s since there is only one candidate.
let subseq: tuple_t!(i32, i32) = tup.subseq();
assert_eq!(subseq, tuple!(12, 24));
source

fn subseq_ref<Seq, I>(&self) -> Seq::AsRefOutput<'_>
where Self: Subseq<Seq, I> + Sized, Seq: TupleLike,

Similar to subseq(), but all its elements are immutable references to the supersequence’s elements.

NOTE: The subsequence must have one and only one candidate in the supersequence.

Rust is almost impossible to infer generic types by the return type annotation, so you need to call it like:

use tuplez::{tuple, TupleLike, tuple_t};

let tup = tuple!(12, "hello", vec![1, 2, 3], 24, 3.14, true);
let subseq = tup.subseq_ref::<tuple_t!(&'static str, bool), _>();
assert_eq!(subseq, tuple!(&"hello", &true));
source

fn subseq_mut<Seq, I>(&mut self) -> Seq::AsMutOutput<'_>
where Self: Subseq<Seq, I> + Sized, Seq: TupleLike,

Similar to subseq(), but all its elements are mutable references to the supersequence’s elements.

NOTE: The subsequence must have one and only one candidate in the supersequence.

Rust is almost impossible to infer generic types by the return type annotation, so you need to call it like:

use tuplez::{get, tuple, TupleLike, tuple_t};

let mut tup = tuple!(12, "hello", vec![1, 2, 3], 24, 3.14, true);
let subseq = tup.subseq_mut::<tuple_t!(&'static str, bool), _>();
*get!(subseq; 0) = "world";
*get!(subseq; 1) = false;
assert_eq!(tup, tuple!(12, "world", vec![1, 2, 3], 24, 3.14, false));
source

fn swap_subseq<Seq, I>(&mut self, subseq: &mut Seq)
where Seq: TupleLike, Self: Subseq<Seq, I>,

Swap elements with a subsequence.

See subseq() to see which inputs are subsequence.

NOTE: The subsequence must have one and only one candidate in the supersequence.

§Example
use tuplez::{tuple, TupleLike};

let mut tup = tuple!(1, Some("hello"), 2, Some(()), 3.14, 3);
let mut tup2 = tuple!(Some("world"), 9.8);
tup.swap_subseq(&mut tup2);
assert_eq!(tup, tuple!(1, Some("world"), 2, Some(()), 9.8, 3));
assert_eq!(tup2, tuple!(Some("hello"), 3.14));
source

fn replace_subseq<Seq, I>(&mut self, subseq: Seq) -> Seq
where Seq: TupleLike, Self: Subseq<Seq, I>,

Replace elements with a subsequence.

See subseq() to see which inputs are subsequence.

NOTE: The subsequence must have one and only one candidate in the supersequence.

It returns a subsequence consisting of the replaced elements.

Hint: If you don’t want to consume the input tuple, then what you are looking for might be swap_subseq().

§Example
use tuplez::{tuple, TupleLike};

let mut tup = tuple!(1, Some("hello"), 2, Some(()), 3.14, 3);
let replaced = tup.replace_subseq(tuple!(Some("world"), 9.8));
assert_eq!(tup, tuple!(1, Some("world"), 2, Some(()), 9.8, 3));
assert_eq!(replaced, tuple!(Some("hello"), 3.14));
source

fn map_replace_subseq<Seq, F, I>(self, f: F) -> Self::MapReplaceOutput
where Seq: TupleLike, Self: SubseqMapReplace<Seq, F, I> + Sized,

Replace elements of specific subsequence with another sequence that may be of different element types.

The elements of new sequence is generated from the user-defined mapper.

Check out Mapper’s documentation page to learn how to build a mapper.

§Example
use std::fmt::Debug;
use tuplez::{mapper, tuple, TupleLike, tuple_t};

let tup = tuple!(1, 3.14, "hello", [1, 2, 3]);
let result = tup.map_replace_subseq::<tuple_t!(f64, [i32; 3]), _, _>(mapper! {
    |x: f64| -> i32 { x as i32 }
    <T: Debug, const N: usize> |x: [T; N]| -> String { format!("{x:?}") }
});
assert_eq!(result, tuple!(1, 3, "hello", "[1, 2, 3]".to_string()))
source

fn foreach_subseq<Seq, F, I>(self, f: F) -> Self::MapReplaceOutput
where Seq: TupleLike, Self: SubseqMapReplace<Seq, F, I> + Sized,

Replace elements of specific subsequence with another sequence that may be of different element types.

Same as map_replace_subseq().

source

fn con_subseq<Seq, I>(self) -> Seq
where Seq: TupleLike, Self: ConSubseq<Seq, I> + Sized,

Take out a contiguous subsequence.

Unlike subseq(), this method requires that all elements of the subsequence are contiguous in the supersequence. Sometimes it can do things that subseq() can’t.

NOTE: The contiguous subsequence must have one and only one candidate in the supersequence.

Add a type annotation to the contiguous subsequence to let con_subseq() know.

§Example
use tuplez::{tuple, TupleLike, tuple_t};

let tup = tuple!(12, "hello", 24, true, false);

// For `subseq`, 4 candidates available:
//      `(12, true)`,
//      `(12, false)`,
//      `(24, true)`,
//      `(24, false)`,
// so this cannot be compiled.
// let subseq: tuple_t!(i32, bool) = tup.subseq();

// But for `con_subseq`,only `(24, true)` is a candidate.
let subseq: tuple_t!(i32, bool) = tup.con_subseq();
assert_eq!(subseq, tuple!(24, true));
source

fn con_subseq_ref<Seq, I>(&self) -> Seq::AsRefOutput<'_>
where Seq: TupleLike, Self: ConSubseq<Seq, I>,

Similar to con_subseq(), but all its elements are immutable references to the supersequence’s elements.

NOTE: The contiguous subsequence must have one and only one candidate in the supersequence.

Rust is almost impossible to infer generic types by the return type annotation, so you need to call it like:

use tuplez::{tuple, TupleLike, tuple_t};

let tup = tuple!(12, "hello", vec![1, 2, 3], 24, 3.14, 36);
let subseq = tup.con_subseq_ref::<tuple_t!(i32, f32), _>();
assert_eq!(subseq, tuple!(&24, &3.14));
source

fn con_subseq_mut<Seq, I>(&mut self) -> Seq::AsMutOutput<'_>
where Seq: TupleLike, Self: ConSubseq<Seq, I>,

Similar to con_subseq(), but all its elements are mutable references to the supersequence’s elements.

NOTE: The contiguous subsequence must have one and only one candidate in the supersequence.

Rust is almost impossible to infer generic types by the return type annotation, so you need to call it like:

use tuplez::{get, tuple, TupleLike, tuple_t};

let mut tup = tuple!(12, "hello", vec![1, 2, 3], "world", 24, 36);
let subseq = tup.con_subseq_mut::<tuple_t!(&'static str, i32), _>();
*get!(subseq; 0) = "rust";
*get!(subseq; 1) = 0;
assert_eq!(tup, tuple!(12, "hello", vec![1, 2, 3], "rust", 0, 36));
source

fn swap_con_subseq<Seq, I>(&mut self, subseq: &mut Seq)
where Seq: TupleLike, Self: ConSubseq<Seq, I>,

Swap elements with a contiguous subsequence.

Unlike swap_subseq(), this method requires that all elements of the subsequence are contiguous in the supersequence. Sometimes it can do things that swap_subseq() can’t.

NOTE: The contiguous subsequence must have one and only one candidate in the supersequence.

§Example
use tuplez::{tuple, TupleLike};

let mut tup = tuple!(1, Some("hello"), 2, Some(()), 3.14, 3);
let mut tup2 = tuple!(4, None::<()>);
tup.swap_con_subseq(&mut tup2);
assert_eq!(tup, tuple!(1, Some("hello"), 4, None::<()>, 3.14, 3));
assert_eq!(tup2, tuple!(2, Some(())));
source

fn replace_con_subseq<Seq, I>(&mut self, subseq: Seq) -> Seq
where Seq: TupleLike, Self: ConSubseq<Seq, I>,

Replace elements with a contiguous subsequence.

Unlike replace_subseq(), this method requires that all elements of the subsequence are contiguous in the supersequence. Sometimes it can do things that replace_subseq() can’t.

NOTE: The contiguous subsequence must have one and only one candidate in the supersequence.

It returns a contiguous subsequence consisting of the replaced elements.

Hint: If you don’t want to consume the input tuple, then what you are looking for might be swap_con_subseq().

§Example
use tuplez::{tuple, TupleLike};

let mut tup = tuple!(1, Some("hello"), 2, Some(()), 3.14, 3);
let replaced = tup.replace_con_subseq(tuple!(4, None::<()>));
assert_eq!(tup, tuple!(1, Some("hello"), 4, None::<()>, 3.14, 3));
assert_eq!(replaced, tuple!(2, Some(())));
source

fn map_replace_con_subseq<Seq, F, I>(self, f: F) -> Self::MapReplaceOutput
where Seq: TupleLike, Self: ConSubseqMapReplace<Seq, F, I> + Sized,

Replace elements of specific contiguous subsequence with another sequence that may be of different element types.

The elements of new sequence is generated from the user-defined mapper.

Check out Mapper’s documentation page to learn how to build a mapper.

§Example
use tuplez::{mapper, tuple, TupleLike, tuple_t};

let tup = tuple!("1", "2", "3", true, false, true);
let result = tup.map_replace_con_subseq::<tuple_t!(&str, bool, bool), _, _>(mapper! {
    |x: &str| -> i32 { x.parse().unwrap() }
    |x: bool| -> bool { !x }
});
assert_eq!(result, tuple!("1", "2", 3, false, true, true));
source

fn foreach_con_subseq<Seq, F, I>(self, f: F) -> Self::MapReplaceOutput
where Seq: TupleLike, Self: ConSubseqMapReplace<Seq, F, I> + Sized,

Replace elements of specific contiguous subsequence with another sequence that may be of different element types.

Same as map_replace_con_subseq().

source

fn subset<Seq, I>(self) -> Seq
where Self: Subseq<Seq, I> + Sized, Seq: TupleLike,

👎Deprecated since 0.10.0: Use subseq() or con_subseq() instead

In the past it was used for the functionality of subseq(), however it did not live up to its name: you actually got a subsequence not a subset while subsets are not required to maintain a consistent element order as the superset.

Therefore, it has been deprecated. You can use subseq() or con_subseq() instead.

source

fn subset_ref<Seq, I>(&self) -> Seq::AsRefOutput<'_>
where Self: Subseq<Seq, I> + Sized, Seq: TupleLike,

👎Deprecated since 0.10.0: Use subseq_ref() or con_subseq_ref() instead

In the past it was used for the functionality of subseq_ref(), however it did not live up to its name: you actually got a subsequence not a subset while subsets are not required to maintain a consistent element order as the superset.

Therefore, it has been deprecated. You can use subseq_ref() or con_subseq_ref() instead.

source

fn subset_mut<Seq, I>(&mut self) -> Seq::AsMutOutput<'_>
where Self: Subseq<Seq, I> + Sized, Seq: TupleLike,

👎Deprecated since 0.10.0: Use subseq_mut() or con_subseq_mut() instead

In the past it was used for the functionality of subseq_mut(), however it did not live up to its name: you actually got a subsequence not a subset while subsets are not required to maintain a consistent element order as the superset.

Therefore, it has been deprecated. You can use subseq_mut() or con_subseq_mut() instead.

source

fn swap_with<Seq, I>(&mut self, subseq: &mut Seq)
where Seq: TupleLike, Self: ConSubseq<Seq, I>,

👎Deprecated since 0.10.0: Use swap(), swap_subseq() or swap_con_subseq() instead

In the past it was used for the functionality of swap_con_subseq(), but with the addition of swap_subseq(), the functionality of this method becomes very unclear.

Therefore, it has been deprecated. You can use swap(), swap_subseq() or swap_con_subseq() instead.

source

fn replace_with<Seq, I>(&mut self, subseq: Seq) -> Seq
where Seq: TupleLike, Self: ConSubseq<Seq, I>,

👎Deprecated since 0.10.0: Use replace(), replace_subseq() or replace_con_subseq() instead

In the past it was used for the functionality of replace_con_subseq(), but with the addition of replace_subseq(), the functionality of this method becomes very unclear.

Therefore, it has been deprecated. You can use replace(), replace_subseq() or replace_con_subseq() instead.

source

fn as_deref(&self) -> Self::AsDerefOutput<'_>
where Self: AsDeref,

Convert from &Tuple<T0, T1, T2, ...> to Tuple<&T0::Target, &T1::Target, &T2::Target, ..> while all the elements of the tuple implement Deref.

§Example
use tuplez::{tuple, TupleLike};

let tup = tuple!(String::from("hello"), Box::new(12), vec![1, 2, 3]);
assert_eq!(tup.as_deref(), tuple!("hello", &12, &[1, 2, 3] as &[_]));
source

fn as_deref_mut(&mut self) -> Self::AsDerefMutOutput<'_>
where Self: AsDerefMut,

Convert from &mut Tuple<T0, T1, T2, ...> to Tuple<&mut T0::Target, &mut T1::Target, &mut T2::Target, ..> while all the elements of the tuple implement DerefMut.

§Example
use tuplez::{tuple, TupleLike, tuple_t};

let mut tup = tuple!(String::from("hello"), Box::new(12), vec![1, 2, 3]);
let _: tuple_t!(&mut str, &mut i32, &mut [i32]) = tup.as_deref_mut();
source

fn cloned(&self) -> Self::ClonedOutput
where Self: Cloned,

If the elements of the tuple are all references, clone its elements to a new tuple.

§Example:
use tuplez::{tuple, TupleLike};

let mut string = String::from("hello");
let tup = tuple!(&1, &mut string, &3.14);
assert_eq!(tup.cloned(), tuple!(1, String::from("hello"), 3.14));
source

fn copied(&self) -> Self::CopiedOutput
where Self: Copied,

If the elements of the tuple are all references, copy its elements to a new tuple.

§Example:
use tuplez::{tuple, TupleLike};

let mut ch = 'c';
let tup = tuple!(&1, &mut ch, &3.14);
assert_eq!(tup.copied(), tuple!(1, 'c', 3.14));
source

fn owned(&self) -> Self::OwnedOutput
where Self: Owned,

Available on crate features std or alloc only.

If the elements of the tuple are all references, clone its elements to a new tuple.

Much like cloned(), but can work on types like &str or slices.

§Example:
use tuplez::{tuple, TupleLike};

let mut arr = [1, 2, 3];
let tup = tuple!(&1, &mut arr as &mut [i32], "hello");
assert_eq!(tup.owned(), tuple!(1, vec![1, 2, 3], "hello".to_string()));
source

fn pop(self) -> (Self::PopBackOutput, Self::PopBackElement)
where Self: Poppable + Sized,

Pop an element from the back of the tuple.

Note: The Unit type is not Poppable.

§Examples
use tuplez::{tuple, TupleLike};

let tup = tuple!(1, "hello", 3.14);
let (tup2, popped) = tup.pop();
assert_eq!(tup2, tuple!(1, "hello"));
assert_eq!(popped, 3.14);
source

fn pop_front(self) -> (Self::PopFrontOutput, Self::PopFrontElement)
where Self: Poppable + Sized,

Pop an element from the front of the tuple.

Note: The Unit type is not Poppable.

§Examples
use tuplez::{tuple, TupleLike};

let tup = tuple!(1, "hello", 3.14);
let (tup2, popped) = tup.pop_front();
assert_eq!(tup2, tuple!("hello", 3.14));
assert_eq!(popped, 1);
source

fn pop_back(self) -> (Self::PopBackOutput, Self::PopBackElement)
where Self: Poppable + Sized,

Pop an element from the back of the tuple. Same as pop().

Note: The Unit type is not Poppable.

source

fn rot_l(self) -> Self::RotLeftOutput
where Self: Rotatable + Sized,

Left rotates the elements of the tuple.

§Examples
use tuplez::{tuple, TupleLike};

let tup = tuple!(1, "2", 3.0, 4);
let tup2 = tup.rot_l();
assert_eq!(tup2, tuple!("2", 3.0, 4, 1));
source

fn rot_r(self) -> Self::RotRightOutput
where Self: Rotatable + Sized,

Right rotates the elements of the tuple.

§Examples
use tuplez::{tuple, TupleLike};

let tup = tuple!(1, "2", 3.0, 4);
let tup2 = tup.rot_r();
assert_eq!(tup2, tuple!(4, 1, "2", 3.0));
source

unsafe fn uninit_assume_init(self) -> Self::Initialized
where Self: Uninit + Sized,

Available on crate feature uninit only.

Extract the values of a tuple consisting of MaybeUninit elements.

§Safety

Same as MaybeUninit::assume_init().

§Example
use tuplez::{tuple, TupleLike, tuple_t};

let mut uninit = <tuple_t!(i32, bool, &str)>::uninit();
uninit.uninit_write_one(12);
uninit.uninit_write_one(true);
uninit.uninit_write_one("hello");
let tup = unsafe { uninit.uninit_assume_init() };
assert_eq!(tup, tuple!(12, true, "hello"));
source

unsafe fn uninit_assume_init_one<T, I>(self) -> Self::MapReplaceOutput<T>
where Self: Search<MaybeUninit<T>, I> + Sized,

Available on crate feature uninit only.

Extract value from a specific MaybeUninit element.

§Safety

Same as MaybeUninit::assume_init().

use std::mem::MaybeUninit;
use tuplez::{get, tuple, TupleLike, tuple_t};

let mut uninit = <tuple_t!(i32, bool, &str)>::uninit();
uninit.uninit_write_one(12);
let first_init = unsafe { uninit.uninit_assume_init_one::<i32, _>() };
assert_eq!(get!(first_init; 0), 12);
let _: tuple_t!(i32, MaybeUninit<bool>, MaybeUninit<&str>) = first_init;
source

unsafe fn uninit_assume_init_read(&self) -> Self::Initialized
where Self: Uninit,

Available on crate feature uninit only.

Read the values of a tuple consisting of MaybeUninit elements.

§Safety

Same as MaybeUninit::assume_init_read().

§Example
use tuplez::{tuple, TupleLike, tuple_t};

let mut uninit = <tuple_t!(i32, Option<Vec<u32>>)>::uninit();
uninit.uninit_write_one(12);
uninit.uninit_write_one(None);
let tup1 = unsafe { uninit.uninit_assume_init_read() };
// SAFETY: `i32` implements `Copy`, duplicating a `None` value is safe.
let tup2 = unsafe { uninit.uninit_assume_init_read() };
assert_eq!(tup1, tup2);
source

unsafe fn uninit_assume_init_read_one<T, I>(&self) -> T
where Self: Search<MaybeUninit<T>, I>,

Available on crate feature uninit only.

Read one value from a specific MaybeUninit element.

§Safety

Same as MaybeUninit::assume_init_read().

§Example
use std::mem::MaybeUninit;
use tuplez::{tuple, TupleLike};

let tup = tuple!(
    0,
    MaybeUninit::<i32>::new(12),
    "hello",
    MaybeUninit::<f64>::uninit(),
    24
);
let x: i32 = unsafe { tup.uninit_assume_init_read_one() };
assert_eq!(x, 12);
source

unsafe fn uninit_assume_init_ref( &self, ) -> <Self::Initialized as TupleLike>::AsRefOutput<'_>
where Self: Uninit,

Available on crate feature uninit only.

Get immutable references to values of a tuple consisting of MaybeUninit elements.

§Safety

Same as MaybeUninit::assume_init_ref().

§Example
use tuplez::{get, tuple, TupleLike, tuple_t};

let mut uninit = <tuple_t!(i32, Vec<i32>)>::uninit();
uninit.uninit_write_one(12);
uninit.uninit_write_one(vec![1, 2, 3]);
let tup_ref = unsafe { uninit.uninit_assume_init_ref() };
assert_eq!(get!(tup_ref; 0), &12);
assert_eq!(get!(tup_ref; 1), &vec![1, 2, 3]);
unsafe { uninit.uninit_assume_init_drop(); }
source

unsafe fn uninit_assume_init_ref_one<T, I>(&self) -> &T
where Self: Search<MaybeUninit<T>, I>,

Available on crate feature uninit only.

Get immutable reference to value of a specific MaybeUninit element.

§Safety

Same as MaybeUninit::assume_init_ref().

§Example
use std::mem::MaybeUninit;
use tuplez::{get, tuple, TupleLike, tuple_t};

let mut tup = tuple!(MaybeUninit::<Vec<i32>>::uninit(), "hello", 12);
tup.uninit_write_one(vec![1, 2, 3]);
let v = unsafe { tup.uninit_assume_init_ref_one::<Vec<i32>, _>() };
assert_eq!(v, &vec![1, 2, 3]);
unsafe { tup.uninit_assume_init_drop_one::<Vec<i32>, _>(); }
source

unsafe fn uninit_assume_init_mut( &mut self, ) -> <Self::Initialized as TupleLike>::AsMutOutput<'_>
where Self: Uninit,

Available on crate feature uninit only.

Get mutable references to values of a tuple consisting of MaybeUninit elements.

§Safety

Same as MaybeUninit::assume_init_mut().

§Example
use tuplez::{get, tuple, TupleLike, tuple_t};

let mut uninit = <tuple_t!(i32, Vec<i32>)>::uninit();
uninit.uninit_write_one(12);
uninit.uninit_write_one(vec![1, 2, 3]);
let tup_mut = unsafe { uninit.uninit_assume_init_mut() };
*get!(tup_mut; 0) += 1;
get!(tup_mut; 1).push(4);
let tup = unsafe { uninit.uninit_assume_init() };
assert_eq!(tup, tuple!(13, vec![1, 2, 3, 4]));
source

unsafe fn uninit_assume_init_mut_one<T, I>(&mut self) -> &mut T
where Self: Search<MaybeUninit<T>, I>,

Available on crate feature uninit only.

Get mutable reference to value of a specific MaybeUninit element.

§Safety

Same as MaybeUninit::assume_init_mut().

§Example
use std::mem::MaybeUninit;
use tuplez::{get, tuple, TupleLike, tuple_t};

let mut tup = tuple!(MaybeUninit::<Vec<i32>>::uninit(), "hello", 12);
tup.uninit_write_one(vec![1, 2, 3]);
let v = unsafe { tup.uninit_assume_init_mut_one::<Vec<i32>, _>() };
v.push(4);
assert_eq!(v, &vec![1, 2, 3, 4]);
unsafe { tup.uninit_assume_init_drop_one::<Vec<i32>, _>(); }
source

unsafe fn uninit_assume_init_drop(&mut self)
where Self: Uninit,

Available on crate feature uninit only.

Drop values in place for a tuple consisting of MaybeUninit elements.

§Safety

Same as MaybeUninit::assume_init_drop().

source

unsafe fn uninit_assume_init_drop_one<T, I>(&mut self)
where Self: Search<MaybeUninit<T>, I>,

Available on crate feature uninit only.

Drop value in place for a specific MaybeUninit element.

§Safety

Same as MaybeUninit::assume_init_drop().

source

fn uninit_as_ptr(&self) -> <Self::Initialized as TupleLike>::AsPtrOutput
where Self: Uninit,

Available on crate feature uninit only.

Get points to values of a tuple consisting of MaybeUninit elements.

§Example
use tuplez::{get, TupleLike, tuple_t};

let mut uninit = <tuple_t!(i32, Vec<i32>)>::uninit();
uninit.uninit_write_one(12);
uninit.uninit_write_one(vec![1, 2, 3]);
let v = unsafe { &*get!(uninit.uninit_as_ptr(); 1) };
assert_eq!(v.len(), 3);
unsafe { uninit.uninit_assume_init_drop(); }
source

fn uninit_as_mut_ptr( &mut self, ) -> <Self::Initialized as TupleLike>::AsMutPtrOutput
where Self: Uninit,

Available on crate feature uninit only.

Get mutable points to values of a tuple consisting of MaybeUninit elements.

§Example
use tuplez::{get, TupleLike, tuple_t};

let mut uninit = <tuple_t!(i32, Vec<i32>)>::uninit();
uninit.uninit_write_one(12);
uninit.uninit_write_one(vec![1, 2, 3]);
let v = unsafe { &mut *get!(uninit.uninit_as_mut_ptr(); 1) };
v.push(4);
assert_eq!(v.len(), 4);
unsafe { uninit.uninit_assume_init_drop(); }
source

fn uninit_write_one<T, I>(&mut self, value: T) -> &mut T
where Self: Search<MaybeUninit<T>, I>,

Available on crate feature uninit only.

Set value to a specific MaybeUninit element in a tuple.

NOTE: The type of this element must exist only once in the tuple.

Similar to MaybeUninit::write(), this overwrites any previous value without dropping it.

§Example
use std::mem::MaybeUninit;
use tuplez::{tuple, TupleLike, tuple_t};

let mut uninit = <tuple_t!(i32, bool, &str)>::uninit();
uninit.uninit_write_one(12);
uninit.uninit_write_one(true);
uninit.uninit_write_one("hello");
let tup = unsafe { uninit.uninit_assume_init() };
assert_eq!(tup, tuple!(12, true, "hello"));

let mut tup = tuple!(
    0,
    MaybeUninit::<i32>::uninit(),
    "hello",
    MaybeUninit::<f64>::uninit(),
    24
);
let x = unsafe { tup.uninit_write_one(12) };
assert_eq!(x, &12);
source

fn uninit_write( &mut self, init: Self::Initialized, ) -> <Self::Initialized as TupleLike>::AsMutOutput<'_>
where Self: Uninit,

Available on crate feature uninit only.

Set values to a tuple consisting of MaybeUninit elements.

Similar to MaybeUninit::write(), this overwrites any previous value without dropping it.

§Example
use tuplez::{tuple, TupleLike, tuple_t};

let mut uninit = <tuple_t!(i32, bool, &str)>::uninit();
uninit.uninit_write(tuple!(12, true, "hello"));
let tup = unsafe { uninit.uninit_assume_init() };
assert_eq!(tup, tuple!(12, true, "hello"));
source

unsafe fn uninit_assume_init_subseq<Seq, I>(self) -> Self::PartiallyInitialized
where Seq: TupleLike, Self: UninitSubseq<Seq, I> + Sized,

Available on crate feature uninit only.

Extract values of a specific subsequence consisting of MaybeUninit elements.

§Safety

Same as MaybeUninit::assume_init().

§Example
use std::mem::MaybeUninit;
use tuplez::{get, tuple, TupleLike, tuple_t};

let mut tup = tuple!(
    12,
    MaybeUninit::<i32>::zeroed(),
    MaybeUninit::<&str>::uninit(),
    MaybeUninit::<Vec<i32>>::uninit(),
    false,
);
tup.uninit_write_one(vec![1, 2, 3]);
let part_init = unsafe {
    tup.uninit_assume_init_subseq::<tuple_t!(i32, Vec<i32>), _>()
};
assert_eq!(get!(part_init; 1), 0);
assert_eq!(get!(part_init; 3), vec![1, 2, 3]);
let _: tuple_t!(i32, i32, MaybeUninit<&str>, Vec<i32>, bool) = part_init;
source

unsafe fn uninit_assume_init_read_subseq<Seq, I>(&self) -> Seq
where Seq: TupleLike, Self: UninitSubseq<Seq, I>,

Available on crate feature uninit only.

Read the values of a specific subsequence consisting of MaybeUninit elements.

§Safety

Same as MaybeUninit::assume_init_read().

§Example
use std::mem::MaybeUninit;
use tuplez::{tuple, TupleLike, tuple_t};

let mut tup = tuple!(
    12,
    MaybeUninit::<i32>::zeroed(),
    MaybeUninit::<&str>::uninit(),
    MaybeUninit::<Vec<i32>>::uninit(),
    false,
);
tup.uninit_write_one(vec![1, 2, 3]);
let inited = unsafe {
    tup.uninit_assume_init_read_subseq::<tuple_t!(i32, Vec<i32>), _>()
};
assert_eq!(inited, tuple!(0, vec![1, 2, 3]));
source

unsafe fn uninit_assume_init_ref_subseq<Seq, I>( &self, ) -> <Seq as TupleLike>::AsRefOutput<'_>
where Seq: TupleLike, Self: UninitSubseq<Seq, I>,

Available on crate feature uninit only.

Get immutable references to values of a specific subsequence consisting of MaybeUninit elements.

§Safety

Same as MaybeUninit::assume_init_ref().

§Example
use std::mem::MaybeUninit;
use tuplez::{tuple, TupleLike, tuple_t};

let mut tup = tuple!(
    12,
    MaybeUninit::<i32>::zeroed(),
    MaybeUninit::<&str>::uninit(),
    MaybeUninit::<Vec<i32>>::uninit(),
    false,
);
tup.uninit_write_one(vec![1, 2, 3]);
let inited_ref = unsafe {
    tup.uninit_assume_init_ref_subseq::<tuple_t!(i32, Vec<i32>), _>()
};
assert_eq!(inited_ref, tuple!(&0, &vec![1, 2, 3]));
unsafe { tup.uninit_assume_init_drop_subseq::<tuple_t!(i32, Vec<i32>), _>() };
source

unsafe fn uninit_assume_init_mut_subseq<Seq, I>( &mut self, ) -> <Seq as TupleLike>::AsMutOutput<'_>
where Seq: TupleLike, Self: UninitSubseq<Seq, I>,

Available on crate feature uninit only.

Get mutable references to values of a specific subsequence consisting of MaybeUninit elements.

§Safety

Same as MaybeUninit::assume_init_mut().

§Example
use std::mem::MaybeUninit;
use tuplez::{get, tuple, TupleLike, tuple_t};

let mut tup = tuple!(
    12,
    MaybeUninit::<i32>::zeroed(),
    MaybeUninit::<&str>::uninit(),
    MaybeUninit::<Vec<i32>>::uninit(),
    false,
);
tup.uninit_write_one(vec![1, 2, 3]);
let inited_mut = unsafe {
    tup.uninit_assume_init_mut_subseq::<tuple_t!(i32, Vec<i32>), _>()
};
*get!(inited_mut; 0) += 1;
get!(inited_mut; 1).push(4);
assert_eq!(inited_mut, tuple!(&mut 1, &mut vec![1, 2, 3, 4]));
unsafe { tup.uninit_assume_init_drop_subseq::<tuple_t!(i32, Vec<i32>), _>() };
source

fn uninit_subseq_as_ptr<Seq, I>(&self) -> <Seq as TupleLike>::AsPtrOutput
where Seq: TupleLike, Self: UninitSubseq<Seq, I>,

Available on crate feature uninit only.

Get pointers to values of a specific subsequence consisting of MaybeUninit elements.

§Example
use std::mem::MaybeUninit;
use tuplez::{get, tuple, TupleLike, tuple_t};

let mut tup = tuple!(
    12,
    MaybeUninit::<i32>::zeroed(),
    MaybeUninit::<&str>::uninit(),
    MaybeUninit::<Vec<i32>>::uninit(),
    false,
);
tup.uninit_write_one(vec![1, 2, 3]);
let inited_ptr = tup.uninit_subseq_as_ptr::<tuple_t!(i32, Vec<i32>), _>();
unsafe {
    assert_eq!(*get!(inited_ptr; 0), 0);
    assert_eq!(*get!(inited_ptr; 1), vec![1, 2, 3]);
    tup.uninit_assume_init_drop_subseq::<tuple_t!(i32, Vec<i32>), _>();
}
source

fn uninit_subseq_as_mut_ptr<Seq, I>( &mut self, ) -> <Seq as TupleLike>::AsMutPtrOutput
where Seq: TupleLike, Self: UninitSubseq<Seq, I>,

Available on crate feature uninit only.

Get mutable pointers to values of a specific subsequence consisting of MaybeUninit elements.

§Example
use std::mem::MaybeUninit;
use tuplez::{get, tuple, TupleLike, tuple_t};

let mut tup = tuple!(
    12,
    MaybeUninit::<i32>::zeroed(),
    MaybeUninit::<&str>::uninit(),
    MaybeUninit::<Vec<i32>>::uninit(),
    false,
);
tup.uninit_write_one(vec![1, 2, 3]);
let inited_ptr = tup.uninit_subseq_as_mut_ptr::<tuple_t!(i32, Vec<i32>), _>();
unsafe {
    *get!(inited_ptr; 0) += 1;
    (*get!(inited_ptr; 1)).push(4);
    assert_eq!(*get!(inited_ptr; 0), 1);
    assert_eq!(*get!(inited_ptr; 1), vec![1, 2, 3, 4]);
    tup.uninit_assume_init_drop_subseq::<tuple_t!(i32, Vec<i32>), _>();
}
source

fn uninit_write_subseq<Seq, I>(&mut self, subseq: Seq) -> Seq::AsMutOutput<'_>
where Seq: TupleLike, Self: UninitSubseq<Seq, I>,

Available on crate feature uninit only.

Set values to a subsequence consisting of MaybeUninit elements.

NOTE: The subsequence must have one and only one candidate in the supersequence.

Similar to MaybeUninit::write(), this overwrites any previous value without dropping it.

§Example
use tuplez::{tuple, TupleLike, tuple_t};

let mut uninit = <tuple_t!(i32, bool, &str)>::uninit();
uninit.uninit_write_one(true);
uninit.uninit_write_subseq(tuple!(12, "hello"));
let tup = unsafe { uninit.uninit_assume_init() };
assert_eq!(tup, tuple!(12, true, "hello"));
source

unsafe fn uninit_assume_init_drop_subseq<Seq, I>(&mut self)
where Seq: TupleLike, Self: UninitSubseq<Seq, I>,

Available on crate feature uninit only.

Drop values in place for a subsequence consisting of MaybeUninit elements.

NOTE: The subsequence must have one and only one candidate in the supersequence.

§Safety

Same as MaybeUninit::assume_init_drop().

source

unsafe fn uninit_assume_init_con_subseq<Seq, I>( self, ) -> Self::PartiallyInitialized
where Seq: TupleLike, Self: UninitConSubseq<Seq, I> + Sized,

Available on crate feature uninit only.

Extract values of a specific contiguous subsequence consisting of MaybeUninit elements.

§Safety

Same as MaybeUninit::assume_init().

§Example
use std::mem::MaybeUninit;
use tuplez::{get, tuple, TupleLike, tuple_t};

let mut tup = tuple!(
    12,
    MaybeUninit::<i32>::zeroed(),
    MaybeUninit::<i32>::new(13),
    MaybeUninit::<Vec<i32>>::uninit(),
    false,
);
tup.uninit_write_one(vec![1, 2, 3]);
let part_init = unsafe {
    tup.uninit_assume_init_con_subseq::<tuple_t!(i32, Vec<i32>), _>()
};
assert_eq!(get!(part_init; 2), 13);
assert_eq!(get!(part_init; 3), vec![1, 2, 3]);
let _: tuple_t!(i32, MaybeUninit<i32>, i32, Vec<i32>, bool) = part_init;
source

unsafe fn uninit_assume_init_read_con_subseq<Seq, I>(&self) -> Seq
where Seq: TupleLike, Self: UninitConSubseq<Seq, I>,

Available on crate feature uninit only.

Read the values of a specific contiguous subsequence consisting of MaybeUninit elements.

§Safety

Same as MaybeUninit::assume_init_read().

§Example
use std::mem::MaybeUninit;
use tuplez::{tuple, TupleLike, tuple_t};

let mut tup = tuple!(
    12,
    MaybeUninit::<i32>::zeroed(),
    MaybeUninit::<i32>::new(13),
    MaybeUninit::<Vec<i32>>::uninit(),
    false,
);
tup.uninit_write_one(vec![1, 2, 3]);
let inited = unsafe {
    tup.uninit_assume_init_read_con_subseq::<tuple_t!(i32, Vec<i32>), _>()
};
assert_eq!(inited, tuple!(13, vec![1, 2, 3]));
source

unsafe fn uninit_assume_init_ref_con_subseq<Seq, I>( &self, ) -> <Seq as TupleLike>::AsRefOutput<'_>
where Seq: TupleLike, Self: UninitConSubseq<Seq, I>,

Available on crate feature uninit only.

Get immutable references to values of a specific contiguous subsequence consisting of MaybeUninit elements.

§Safety

Same as MaybeUninit::assume_init_ref().

§Example
use std::mem::MaybeUninit;
use tuplez::{tuple, TupleLike, tuple_t};

let mut tup = tuple!(
    12,
    MaybeUninit::<i32>::zeroed(),
    MaybeUninit::<i32>::new(13),
    MaybeUninit::<Vec<i32>>::uninit(),
    false,
);
tup.uninit_write_one(vec![1, 2, 3]);
let inited_ref = unsafe {
    tup.uninit_assume_init_ref_con_subseq::<tuple_t!(i32, Vec<i32>), _>()
};
assert_eq!(inited_ref, tuple!(&13, &vec![1, 2, 3]));
unsafe { tup.uninit_assume_init_drop_con_subseq::<tuple_t!(i32, Vec<i32>), _>() };
source

unsafe fn uninit_assume_init_mut_con_subseq<Seq, I>( &mut self, ) -> <Seq as TupleLike>::AsMutOutput<'_>
where Seq: TupleLike, Self: UninitConSubseq<Seq, I>,

Available on crate feature uninit only.

Get mutable references to values of a specific contiguous subsequence consisting of MaybeUninit elements.

§Safety

Same as MaybeUninit::assume_init_mut().

§Example
use std::mem::MaybeUninit;
use tuplez::{get, tuple, TupleLike, tuple_t};

let mut tup = tuple!(
    12,
    MaybeUninit::<i32>::zeroed(),
    MaybeUninit::<i32>::new(13),
    MaybeUninit::<Vec<i32>>::uninit(),
    false,
);
tup.uninit_write_one(vec![1, 2, 3]);
let inited_mut = unsafe {
    tup.uninit_assume_init_mut_con_subseq::<tuple_t!(i32, Vec<i32>), _>()
};
*get!(inited_mut; 0) += 1;
get!(inited_mut; 1).push(4);
assert_eq!(inited_mut, tuple!(&mut 14, &mut vec![1, 2, 3, 4]));
unsafe { tup.uninit_assume_init_drop_con_subseq::<tuple_t!(i32, Vec<i32>), _>() };
source

fn uninit_con_subseq_as_ptr<Seq, I>(&self) -> <Seq as TupleLike>::AsPtrOutput
where Seq: TupleLike, Self: UninitConSubseq<Seq, I>,

Available on crate feature uninit only.

Get pointers to values of a specific contiguous subsequence consisting of MaybeUninit elements.

§Example
use std::mem::MaybeUninit;
use tuplez::{get, tuple, TupleLike, tuple_t};

let mut tup = tuple!(
    12,
    MaybeUninit::<i32>::zeroed(),
    MaybeUninit::<i32>::new(13),
    MaybeUninit::<Vec<i32>>::uninit(),
    false,
);
tup.uninit_write_one(vec![1, 2, 3]);
let inited_ptr = tup.uninit_con_subseq_as_ptr::<tuple_t!(i32, Vec<i32>), _>();
unsafe {
    assert_eq!(*get!(inited_ptr; 0), 13);
    assert_eq!(*get!(inited_ptr; 1), vec![1, 2, 3]);
    tup.uninit_assume_init_drop_con_subseq::<tuple_t!(i32, Vec<i32>), _>();
}
source

fn uninit_con_subseq_as_mut_ptr<Seq, I>( &mut self, ) -> <Seq as TupleLike>::AsMutPtrOutput
where Seq: TupleLike, Self: UninitConSubseq<Seq, I>,

Available on crate feature uninit only.

Get mutable pointers to values of a specific contiguous subsequence consisting of MaybeUninit elements.

§Example
use std::mem::MaybeUninit;
use tuplez::{get, tuple, TupleLike, tuple_t};

let mut tup = tuple!(
    12,
    MaybeUninit::<i32>::zeroed(),
    MaybeUninit::<i32>::new(13),
    MaybeUninit::<Vec<i32>>::uninit(),
    false,
);
tup.uninit_write_one(vec![1, 2, 3]);
let inited_ptr = tup.uninit_con_subseq_as_mut_ptr::<tuple_t!(i32, Vec<i32>), _>();
unsafe {
    *get!(inited_ptr; 0) += 1;
    (*get!(inited_ptr; 1)).push(4);
    assert_eq!(*get!(inited_ptr; 0), 14);
    assert_eq!(*get!(inited_ptr; 1), vec![1, 2, 3, 4]);
    tup.uninit_assume_init_drop_con_subseq::<tuple_t!(i32, Vec<i32>), _>();
}
source

fn uninit_write_con_subseq<Seq, I>( &mut self, subseq: Seq, ) -> Seq::AsMutOutput<'_>
where Seq: TupleLike, Self: UninitConSubseq<Seq, I>,

Available on crate feature uninit only.

Set values to a contiguous subsequence consisting of MaybeUninit elements.

Similar to MaybeUninit::write(), this overwrites any previous value without dropping it.

NOTE: The contiguous subsequence must have one and only one candidate in the supersequence.

§Example
use tuplez::{tuple, TupleLike, tuple_t};

let mut uninit = <tuple_t!(i32, bool, &str)>::uninit();
uninit.uninit_write_one(true);
uninit.uninit_write_subseq(tuple!(12, "hello"));
let tup = unsafe { uninit.uninit_assume_init() };
assert_eq!(tup, tuple!(12, true, "hello"));
source

unsafe fn uninit_assume_init_drop_con_subseq<Seq, I>(&mut self)
where Seq: TupleLike, Self: UninitConSubseq<Seq, I>,

Available on crate feature uninit only.

Drop values in place for a contiguous subsequence consisting of MaybeUninit elements.

NOTE: The contiguous subsequence must have one and only one candidate in the supersequence.

§Safety

Same as MaybeUninit::assume_init_drop().

source

fn untuple(self) -> Self::UntupleOutput
where Self: Untupleable + Sized,

Untuple a tuple, whose elements are all tuples.

See to_tuple() for the opposite operation.

Also called flatten().

§Example
use tuplez::{tuple, TupleLike};

let tup_tup = tuple!(tuple!(1, "hello"), tuple!(), tuple!(3.14));
assert_eq!(tup_tup.untuple(), tuple!(1, "hello", 3.14));
source

fn flatten(self) -> Self::UntupleOutput
where Self: Untupleable + Sized,

Flatten one level of nesting in the tuple.

Also called untuple().

§Example
use tuplez::{tuple, TupleLike};

let tup_tup = tuple!(tuple!(1, "hello"), tuple!(), tuple!(3.14));
assert_eq!(tup_tup.flatten(), tuple!(1, "hello", 3.14));
source

fn foreach<F>(self, mapper: F) -> <Self as Foreach<F>>::Output
where Self: Foreach<F> + Sized,

Traverse the tuple, and collect the output of traversal into a new tuple.

Check out Mapper’s documentation page to learn how to build a mapper that can be passed to foreach().

NOTE: Traverse a tuple will consume it. If this is not what you want, call as_ref() or as_mut() to create a new tuple that references its all members before traversing.

§Example
use tuplez::{mapper, tuple, TupleLike};

let tup = tuple!(1, "hello", 3.14).foreach(mapper! {
    |x: i32| -> i64 { x as i64 }
    |x: f32| -> String { x.to_string() }
    <'a> |x: &'a str| -> &'a [u8] { x.as_bytes() }
});
assert_eq!(tup, tuple!(1i64, b"hello" as &[u8], "3.14".to_string()));
source

fn fold<F, Acc>(self, folder: F, acc: Acc) -> <Self as Foldable<F, Acc>>::Output
where Self: Foldable<F, Acc> + Sized,

Fold the tuple.

Check out Folder’s documentation page to learn how to build a folder that can be passed to foreach().

NOTE: Fold a tuple will consume it. If this is not what you want, call as_ref() or as_mut() to create a new tuple that references its all members before folding.

§Example
use tuplez::{folder, tuple, TupleLike};

let tup = tuple!(Some(1), "2", Some(3.0));
let result = tup.fold(
    folder! { String; // Type of `acc` of all closures must be the same and annotated at the front
        |acc, x: &str| { acc + &x.to_string() }
        <T: ToString> |acc, x: Option<T>| { acc + &x.unwrap().to_string() }
    },
    String::new(),
);
assert_eq!(result, "123".to_string());
source

fn any<Pred>(&self, predicate: Pred) -> bool
where Self: TestAny<Pred>,

Tests if any element of the tuple matches a predicate.

Check out UnaryPredicate’s documentation page to learn how to build a unary predicate that can be passed to any().

any() is short-circuiting; in other words, it will stop processing as soon as it finds a true, given that no matter what else happens, the result will also be true.

An empty tuple returns false.

§Example
use tuplez::{tuple, TupleLike, unary_pred};

let predicate = unary_pred! {
    |x: i32| { (0..10).contains(x) },
    |x: &str| { x.parse::<i32>().is_ok() },
};

let tup = tuple!(100, 2, "world");
let result = tup.any(predicate);
assert_eq!(result, true);

let tup = tuple!(-1, 96, "hello");
let result = tup.any(predicate);
assert_eq!(result, false);
source

fn all<Pred>(&self, predicate: Pred) -> bool
where Self: TestAll<Pred>,

Tests if every element of the tuple matches a predicate.

Check out UnaryPredicate’s documentation page to learn how to build a unary predicate that can be passed to all().

all() is short-circuiting; in other words, it will stop processing as soon as it finds a false, given that no matter what else happens, the result will also be false.

An empty tuple returns true.

§Example
use tuplez::{tuple, TupleLike, unary_pred};

let predicate = unary_pred! {
    |x: i32| { (0..10).contains(x) },
    |x: &str| { x.parse::<i32>().is_ok() },
};

let tup = tuple!(1, 2, "3");
let result = tup.all(predicate);
assert_eq!(result, true);

let tup = tuple!(7, 8, "hello");
let result = tup.all(predicate);
assert_eq!(result, false);
source

fn dot<T>(self, rhs: T) -> <Self as Dot<T>>::Output
where Self: Dot<T> + Sized,

Performs dot product operation.

Note: it evaluates starting from the last element.

§Example
use tuplez::{tuple, TupleLike};
assert_eq!(tuple!(1, 3, -5).dot(tuple!(4, -2, -1)), 3);
source

fn zip<T>(self, rhs: T) -> Self::ZipOutput
where Self: Zippable<T> + Sized,

Zip two tuples.

See unzip() for the opposite operation.

§Example
use tuplez::{tuple, TupleLike};

let tup = tuple!(1, 2.0, "3").zip(tuple!("4", 5, 6.0));
assert_eq!(tup, tuple!(tuple!(1, "4"), tuple!(2.0, 5), tuple!("3", 6.0)));
source

fn zip2<T>(self, rhs: T) -> Self::ZipOutput2
where Self: Zippable<T> + Sized,

Zip two tuples, but output elements are primitive tuples.

See unzip() for the opposite operation.

§Example
use tuplez::{tuple, TupleLike};

let tup = tuple!(1, 2.0, "3").zip2(tuple!("4", 5, 6.0));
assert_eq!(tup, tuple!((1, "4"), (2.0, 5), ("3", 6.0)));
source

fn unzip(self) -> (Self::UnzipOutputLeft, Self::UnzipOutputRight)
where Self: Unzippable + Sized,

Unzip a tuple to two tuples, if all elements of the tuple are tuples with two elements. Elements can be of Tuple type or primitive tuple type.

See zip() and zip2() for the opposite operation.

use tuplez::{tuple, TupleLike};

let tup = tuple!(
    tuple!(1, "hello"), // A `Tuple`
    ("world", 2.0),     // A primitive tuple
);
let (l, r) = tup.unzip();
assert_eq!(l, tuple!(1, "world"));
assert_eq!(r, tuple!("hello", 2.0));
source

fn extend<T>(self, rhs: T) -> Self::ExtendBackOutput
where Self: Extendable<T> + Sized,

If the elements of a tuple are all tuples, push an element to the back of each tuple element.

See shrink() for the opposite operation.

§Example
use tuplez::{tuple, TupleLike};

let tup = tuple!(tuple!(1, "hello"), tuple!(), tuple!(3.14));
let ext = tuple!(9.0, "8", 7);
assert_eq!(
    tup.extend(ext),
    tuple!(tuple!(1, "hello", 9.0), tuple!("8"), tuple!(3.14, 7))
);
source

fn extend_front<T>(self, rhs: T) -> Self::ExtendFrontOutput
where Self: Extendable<T> + Sized,

If the elements of a tuple are all tuples, push an element to the front of each tuple element.

See shrink_front() for the opposite operation.

§Example
use tuplez::{tuple, TupleLike};

let tup = tuple!(tuple!(1, "hello"), tuple!(), tuple!(3.14));
let ext = tuple!(9.0, "8", 7);
assert_eq!(
    tup.extend_front(ext),
    tuple!(tuple!(9.0, 1, "hello"), tuple!("8"), tuple!(7, 3.14))
);
source

fn extend_back<T>(self, rhs: T) -> Self::ExtendBackOutput
where Self: Extendable<T> + Sized,

If the elements of a tuple are all tuples, push an element to the front of each tuple element. Same as extend().

source

fn shrink(self) -> (Self::ShrinkBackOutput, Self::ShrinkBackElements)
where Self: Shrinkable + Sized,

If the elements of a tuple are all tuples, pop an element from the back of each tuple element.

See extend() for the opposite operation.

§Example
use tuplez::{tuple, TupleLike};

let tup = tuple!(tuple!(9.0, 1, "hello"), tuple!("8"), tuple!(7, 3.14));
let (result, popped) = tup.shrink();
assert_eq!(result, tuple!(tuple!(9.0, 1), tuple!(), tuple!(7)));
assert_eq!(popped, tuple!("hello", "8", 3.14));
source

fn shrink_front(self) -> (Self::ShrinkFrontOutput, Self::ShrinkFrontElements)
where Self: Shrinkable + Sized,

If the elements of a tuple are all tuples, pop an element from the front of each tuple element.

See extend_front() for the opposite operation.

§Example
use tuplez::{tuple, TupleLike};

let tup = tuple!(tuple!(9.0, 1, "hello"), tuple!("8"), tuple!(7, 3.14));
let (result, popped) = tup.shrink_front();
assert_eq!(result, tuple!(tuple!(1, "hello"), tuple!(), tuple!(3.14)));
assert_eq!(popped, tuple!(9.0, "8", 7));
source

fn shrink_back(self) -> (Self::ShrinkBackOutput, Self::ShrinkBackElements)
where Self: Shrinkable + Sized,

If the elements of a tuple are all tuples, pop an element from the back of each tuple element. Same as shrink().

source

fn combine<T>(self, rhs: T) -> Self::CombineOutput
where Self: Combinable<T> + Sized,

If two tuples have the same number of elements, and their elements are both tuples, join their tuple elements one-to-one.

NOTE: This method is not join().

§Example
use tuplez::{tuple, TupleLike};

let tup = tuple!(tuple!(1), tuple!(), tuple!("hello", 3.14));
let tup2 = tuple!(tuple!(), tuple!(9, "8"), tuple!(7.0));
let tup3 = tup.combine(tup2);
assert_eq!(tup3, tuple!(tuple!(1), tuple!(9, "8"), tuple!("hello", 3.14, 7.0)));
source

fn replace_head<T>(self, rhs: T) -> (Self::ReplaceOutput, Self::Replaced)
where T: TupleLike, Self: HeadReplaceable<T> + Sized,

Replace the first N elements of the tuple with all elements of another tuple of N elements.

§Example
use tuplez::{tuple, TupleLike};

let tup = tuple!(1, "2", 3.0, Some(4));
let tup2 = tuple!("z", 8);
let (output, replaced) = tup.replace_head(tup2);
assert_eq!(output, tuple!("z", 8, 3.0, Some(4)));
assert_eq!(replaced, tuple!(1, "2"));
source

fn replace_tail<T, I>(self, rhs: T) -> (Self::ReplaceOutput, Self::Replaced)
where T: TupleLike, Self: TailReplaceable<T, I> + Sized,

Replace the last N elements of the tuple with all elements of another tuple of N elements.

§Example
use tuplez::{tuple, TupleLike};

let tup = tuple!(1, "2", 3.0, Some(4));
let tup2 = tuple!("z", 8);
let (output, replaced) = tup.replace_tail(tup2);
assert_eq!(output, tuple!(1, "2", "z", 8));
assert_eq!(replaced, tuple!(3.0, Some(4)));
source

fn call<T, P>(&self, rhs: T) -> <Self as Callable<T, P>>::Output
where Self: Callable<T, P>,

When all elements of the tuple implement Fn(T) for a specific T, call them once in sequence.

§Example

It is required that T implements Clone.

use tuplez::{tuple, TupleLike};

fn add1(x: i32) -> i32 {
    x + 1
}
fn add2(x: i32) -> i32 {
    x + 2
}
fn to_string(x: i32) -> String {
    x.to_string()
}

let tup = tuple!(add1, add2, to_string).call(1);
assert_eq!(tup, tuple!(2, 3, "1".to_string()));

…however, due to the existence of reborrowing, we can use some tricks to allow the mutable references to be used as parameters multiple times.

use tuplez::{tuple, TupleLike};

fn add1(x: &mut i32) {
    *x += 1
}
fn add2(x: &mut i32) {
    *x += 2
}
fn to_string(x: &mut i32) -> String {
    x.to_string()
}

let mut x = 1;
let tup = tuple!(add1, add2, to_string).call(&mut x);
assert_eq!(x, 4);
assert_eq!(tup, tuple!((), (), "4".to_string()));
source

fn call_mut<T, P>(&mut self, rhs: T) -> <Self as MutCallable<T, P>>::Output
where Self: MutCallable<T, P>,

When all elements of the tuple implement FnMut(T) for a specific T, call them once in sequence.

Basically the same as call(), but elements are required to implement FnMut(T) instead of Fn(T).

source

fn call_once<T, P>(self, rhs: T) -> <Self as OnceCallable<T, P>>::Output
where Self: OnceCallable<T, P> + Sized,

When all elements of the tuple implement FnOnce(T) for a specific T, call them once in sequence.

Basically the same as call(), but elements are required to implement FnOnce(T) instead of Fn(T).

source

fn unwrap(self) -> Self::UnwrapOutput
where Self: Unwrap + Sized,

Available on crate feature unwrap only.

Convert from Tuple<Wrapper0<T0>, Wrapper1<T1>, ... Wrappern<Tn>> to Tuple<T0, T1, ..., Tn>, when all element types Wrapper0, Wrapper1Wrappern implement Unwrap.

Because this function may panic, its use is generally discouraged. Instead, use unwrap_or_default() or try_unwrap().

§Panic

Panic if any element does not contain a value.

§Example
use tuplez::{tuple, TupleLike};

let tup = tuple!(Some(1), Ok::<f32, ()>(3.14), Some("hello"));
assert_eq!(tup.unwrap(), tuple!(1, 3.14, "hello"));
source

fn has_value(&self) -> bool
where Self: Unwrap,

Available on crate feature unwrap only.

Check if self can be safely unwrap().

§Example
use tuplez::{tuple, TupleLike};

assert_eq!(tuple!(Some(1), Some(3.14), Ok::<&str, ()>("hello")).has_value(), true);
assert_eq!(tuple!(None::<i32>, Some(3.14), Err::<&str, ()>(())).has_value(), false);
source

fn unwrap_or_default(self) -> Self::UnwrapOutput
where Self: UnwrapOrDefault + Sized,

Available on crate feature unwrap only.

Convert from Tuple<Wrapper0<T0>, Wrapper1<T1>, ... Wrappern<Tn>> to Tuple<T0, T1, ..., Tn>, when all element types Wrapper0, Wrapper1Wrappern implement UnwrapOrDefault.

Unlike unwrap(), if an element does not contain a value, use the default value instead of panic.

§Example
use tuplez::{tuple, TupleLike};

let tup = tuple!(Some(1), Err::<f32, &str>("failed"), Some("hello"));
assert_eq!(tup.unwrap_or_default(), tuple!(1, 0.0, "hello"));
source

fn try_unwrap(self) -> Option<Self::UnwrapOutput>
where Self: Unwrap + Sized,

Available on crate feature unwrap only.

Convert from Tuple<Wrapper0<T0>, Wrapper1<T1>, ... Wrappern<Tn>> to Option<Tuple<T0, T1, ..., Tn>>, when all element types Wrapper0, Wrapper1Wrappern implement Unwrap.

§Example
use tuplez::{tuple, TupleLike};

let tup = tuple!(Some(1), Ok::<f32, ()>(3.14));
assert_eq!(tup.try_unwrap(), Some(tuple!(1, 3.14)));
let tup2 = tuple!(Some("hello"), Err::<i32, &str>("failed"));
assert_eq!(tup2.try_unwrap(), None);

Object Safety§

This trait is not object safe.

Implementors§

source§

impl TupleLike for Unit

source§

impl<First, Other> TupleLike for Tuple<First, Other>
where Other: TupleLike,

§

type AsRefOutput<'a> = Tuple<&'a First, <Other as TupleLike>::AsRefOutput<'a>> where Self: 'a

§

type AsMutOutput<'a> = Tuple<&'a mut First, <Other as TupleLike>::AsMutOutput<'a>> where Self: 'a

§

type AsPtrOutput = Tuple<*const First, <Other as TupleLike>::AsPtrOutput>

§

type AsMutPtrOutput = Tuple<*mut First, <Other as TupleLike>::AsMutPtrOutput>

§

type AsPinRefOutput<'a> = Tuple<Pin<&'a First>, <Other as TupleLike>::AsPinRefOutput<'a>> where Self: 'a

§

type AsPinMutOutput<'a> = Tuple<Pin<&'a mut First>, <Other as TupleLike>::AsPinMutOutput<'a>> where Self: 'a

§

type PushFrontOutput<T> = Tuple<T, Tuple<First, Other>>

§

type PushBackOutput<T> = Tuple<First, <Other as TupleLike>::PushBackOutput<T>>

§

type RevOutput = <<Other as TupleLike>::RevOutput as TupleLike>::PushBackOutput<First>

§

type JoinOutput<T> = Tuple<First, <Other as TupleLike>::JoinOutput<T>> where T: TupleLike

§

type ToSomeOutput = Tuple<Option<First>, <Other as TupleLike>::ToSomeOutput>

§

type ToOkOutput<E> = Tuple<Result<First, E>, <Other as TupleLike>::ToOkOutput<E>>

§

type ToTupleOutput = Tuple<Tuple<First, Unit>, <Other as TupleLike>::ToTupleOutput>

§

type Uninit = Tuple<MaybeUninit<First>, <Other as TupleLike>::Uninit>

source§

const LEN: usize = _