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§
sourcetype AsRefOutput<'a>: TupleLike
where
Self: 'a
type AsRefOutput<'a>: TupleLike where Self: 'a
The type of tuple containing immutable references to all elements of the tuple.
sourcetype AsMutOutput<'a>: TupleLike
where
Self: 'a
type AsMutOutput<'a>: TupleLike where Self: 'a
The type of tuple containing mutable references to all elements of the tuple.
sourcetype AsPtrOutput: TupleLike
type AsPtrOutput: TupleLike
The type of tuple containing pointers to all elements of the tuple.
sourcetype AsMutPtrOutput: TupleLike
type AsMutPtrOutput: TupleLike
The type of tuple containing mutable pointers to all elements of the tuple.
sourcetype AsPinRefOutput<'a>: TupleLike
where
Self: 'a
type AsPinRefOutput<'a>: TupleLike where Self: 'a
The type of tuple containing Pin
s of immutable references to all elements of the tuple.
sourcetype AsPinMutOutput<'a>: TupleLike
where
Self: 'a
type AsPinMutOutput<'a>: TupleLike where Self: 'a
The type of tuple containing Pin
s of mutable references to all elements of the tuple.
sourcetype PushFrontOutput<T>: TupleLike
type PushFrontOutput<T>: TupleLike
The type of tuple generated by pushing an element to the front of the tuple.
sourcetype PushBackOutput<T>: TupleLike
type PushBackOutput<T>: TupleLike
The type of tuple generated by pushing an element to the back of the tuple.
sourcetype JoinOutput<T>: TupleLike
where
T: TupleLike
type JoinOutput<T>: TupleLike where T: TupleLike
The type of tuple generated by joining two tuples.
sourcetype ToSomeOutput: TupleLike
type ToSomeOutput: TupleLike
The type of tuple after wrapping all elements into Option
.
sourcetype ToOkOutput<E>: TupleLike
type ToOkOutput<E>: TupleLike
The type of tuple after wrapping all elements into Result
.
sourcetype ToTupleOutput: TupleLike
type ToTupleOutput: TupleLike
The type of tuple after wrapping all elements into Tuple
.
sourcetype Uninit: TupleLike
Available on crate feature uninit
only.
type Uninit: TupleLike
uninit
only.The type of tuple after wrapping all elements into MaybeUninit
.
Required Associated Constants§
Required Methods§
sourcefn as_ref(&self) -> Self::AsRefOutput<'_>
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")));
sourcefn as_mut(&mut self) -> Self::AsMutOutput<'_>
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"));
sourcefn as_ptr(&self) -> Self::AsPtrOutput
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);
sourcefn as_mut_ptr(&mut self) -> Self::AsMutPtrOutput
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);
sourcefn as_pin_ref(self: Pin<&Self>) -> Self::AsPinRefOutput<'_>
fn as_pin_ref(self: Pin<&Self>) -> Self::AsPinRefOutput<'_>
Convert from Pin<&Tuple<T0, T1, T2, ..>
to Tuple<Pin<&T0>, Pin<&T1>, Pin<&T2>, ...>
.
sourcefn as_pin_mut(self: Pin<&mut Self>) -> Self::AsPinMutOutput<'_>
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>, ...>
.
sourcefn push<T>(self, value: T) -> Self::PushBackOutput<T>
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));
sourcefn push_front<T>(self, value: T) -> Self::PushFrontOutput<T>
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));
sourcefn push_back<T>(self, value: T) -> Self::PushBackOutput<T>
fn push_back<T>(self, value: T) -> Self::PushBackOutput<T>
Push an element to the back of the tuple. Same as push()
.
sourcefn rev(self) -> Self::RevOutput
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));
sourcefn join<T>(self, value: T) -> Self::JoinOutput<T>where
T: TupleLike,
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"));
sourcefn to_some(self) -> Self::ToSomeOutput
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)));
sourcefn to_ok<E>(self) -> Self::ToOkOutput<E>
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)));
sourcefn to_tuple(self) -> Self::ToTupleOutput
fn to_tuple(self) -> Self::ToTupleOutput
sourcefn uninit() -> Self::Uninit
Available on crate feature uninit
only.
fn uninit() -> Self::Uninit
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;
sourcefn zeroed() -> Self::Uninit
Available on crate feature uninit
only.
fn zeroed() -> Self::Uninit
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()));
sourcefn to_uninit(self) -> Self::Uninit
Available on crate feature uninit
only.
fn to_uninit(self) -> Self::Uninit
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§
sourcefn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Creates a “by reference” adapter for this instance.
It will simply borrow this current tuple.
sourcefn enumerate(self) -> Self::EnumerateOutputwhere
Self: Sized + Enumerable,
fn enumerate(self) -> Self::EnumerateOutputwhere
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)),
));
sourcefn take<T, I>(self) -> (T, Self::TakeRemainder)
fn take<T, I>(self) -> (T, Self::TakeRemainder)
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]));
sourcefn get_ref<T, I>(&self) -> &T
fn get_ref<T, I>(&self) -> &T
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]);
sourcefn get_mut<T, I>(&mut self) -> &mut T
fn get_mut<T, I>(&mut self) -> &mut T
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]));
sourcefn swap<T, I>(&mut self, value: &mut T)where
Self: Search<T, I>,
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");
sourcefn replace<T, I>(&mut self, value: T) -> Twhere
Self: Search<T, I>,
fn replace<T, I>(&mut self, value: T) -> Twhere
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");
sourcefn map_replace<T, U, F, I>(self, f: F) -> Self::MapReplaceOutput<U>
fn map_replace<T, U, F, I>(self, f: F) -> Self::MapReplaceOutput<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])))
sourcefn subseq<Seq, I>(self) -> Seq
fn subseq<Seq, I>(self) -> Seq
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));
sourcefn subseq_ref<Seq, I>(&self) -> Seq::AsRefOutput<'_>
fn subseq_ref<Seq, I>(&self) -> Seq::AsRefOutput<'_>
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));
sourcefn subseq_mut<Seq, I>(&mut self) -> Seq::AsMutOutput<'_>
fn subseq_mut<Seq, I>(&mut self) -> Seq::AsMutOutput<'_>
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));
sourcefn swap_subseq<Seq, I>(&mut self, subseq: &mut Seq)
fn swap_subseq<Seq, I>(&mut self, subseq: &mut Seq)
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));
sourcefn replace_subseq<Seq, I>(&mut self, subseq: Seq) -> Seq
fn replace_subseq<Seq, I>(&mut self, subseq: Seq) -> Seq
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));
sourcefn map_replace_subseq<Seq, F, I>(self, f: F) -> Self::MapReplaceOutput
fn map_replace_subseq<Seq, F, I>(self, f: F) -> Self::MapReplaceOutput
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()))
sourcefn foreach_subseq<Seq, F, I>(self, f: F) -> Self::MapReplaceOutput
fn foreach_subseq<Seq, F, I>(self, f: F) -> Self::MapReplaceOutput
Replace elements of specific subsequence with another sequence that may be of different element types.
Same as map_replace_subseq()
.
sourcefn con_subseq<Seq, I>(self) -> Seq
fn con_subseq<Seq, I>(self) -> Seq
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));
sourcefn con_subseq_ref<Seq, I>(&self) -> Seq::AsRefOutput<'_>
fn con_subseq_ref<Seq, I>(&self) -> Seq::AsRefOutput<'_>
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));
sourcefn con_subseq_mut<Seq, I>(&mut self) -> Seq::AsMutOutput<'_>
fn con_subseq_mut<Seq, I>(&mut self) -> Seq::AsMutOutput<'_>
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));
sourcefn swap_con_subseq<Seq, I>(&mut self, subseq: &mut Seq)
fn swap_con_subseq<Seq, I>(&mut self, subseq: &mut Seq)
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(())));
sourcefn replace_con_subseq<Seq, I>(&mut self, subseq: Seq) -> Seq
fn replace_con_subseq<Seq, I>(&mut self, subseq: Seq) -> Seq
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(())));
sourcefn map_replace_con_subseq<Seq, F, I>(self, f: F) -> Self::MapReplaceOutput
fn map_replace_con_subseq<Seq, F, I>(self, f: F) -> Self::MapReplaceOutput
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));
sourcefn foreach_con_subseq<Seq, F, I>(self, f: F) -> Self::MapReplaceOutput
fn foreach_con_subseq<Seq, F, I>(self, f: F) -> Self::MapReplaceOutput
Replace elements of specific contiguous subsequence with another sequence that may be of different element types.
Same as map_replace_con_subseq()
.
sourcefn subset<Seq, I>(self) -> Seq
👎Deprecated since 0.10.0: Use subseq() or con_subseq() instead
fn subset<Seq, I>(self) -> Seq
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.
sourcefn subset_ref<Seq, I>(&self) -> Seq::AsRefOutput<'_>
👎Deprecated since 0.10.0: Use subseq_ref() or con_subseq_ref() instead
fn subset_ref<Seq, I>(&self) -> Seq::AsRefOutput<'_>
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.
sourcefn subset_mut<Seq, I>(&mut self) -> Seq::AsMutOutput<'_>
👎Deprecated since 0.10.0: Use subseq_mut() or con_subseq_mut() instead
fn subset_mut<Seq, I>(&mut self) -> Seq::AsMutOutput<'_>
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.
sourcefn swap_with<Seq, I>(&mut self, subseq: &mut Seq)
👎Deprecated since 0.10.0: Use swap(), swap_subseq() or swap_con_subseq() instead
fn swap_with<Seq, I>(&mut self, subseq: &mut Seq)
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.
sourcefn replace_with<Seq, I>(&mut self, subseq: Seq) -> Seq
👎Deprecated since 0.10.0: Use replace(), replace_subseq() or replace_con_subseq() instead
fn replace_with<Seq, I>(&mut self, subseq: Seq) -> Seq
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.
sourcefn as_deref(&self) -> Self::AsDerefOutput<'_>where
Self: AsDeref,
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 &[_]));
sourcefn as_deref_mut(&mut self) -> Self::AsDerefMutOutput<'_>where
Self: AsDerefMut,
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();
sourcefn cloned(&self) -> Self::ClonedOutputwhere
Self: Cloned,
fn cloned(&self) -> Self::ClonedOutputwhere
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));
sourcefn copied(&self) -> Self::CopiedOutputwhere
Self: Copied,
fn copied(&self) -> Self::CopiedOutputwhere
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));
sourcefn owned(&self) -> Self::OwnedOutputwhere
Self: Owned,
Available on crate features std
or alloc
only.
fn owned(&self) -> Self::OwnedOutputwhere
Self: Owned,
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()));
sourcefn pop(self) -> (Self::PopBackOutput, Self::PopBackElement)
fn pop(self) -> (Self::PopBackOutput, Self::PopBackElement)
sourcefn pop_front(self) -> (Self::PopFrontOutput, Self::PopFrontElement)
fn pop_front(self) -> (Self::PopFrontOutput, Self::PopFrontElement)
sourcefn pop_back(self) -> (Self::PopBackOutput, Self::PopBackElement)
fn pop_back(self) -> (Self::PopBackOutput, Self::PopBackElement)
sourcefn rot_l(self) -> Self::RotLeftOutput
fn rot_l(self) -> Self::RotLeftOutput
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));
sourcefn rot_r(self) -> Self::RotRightOutput
fn rot_r(self) -> Self::RotRightOutput
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));
sourceunsafe fn uninit_assume_init(self) -> Self::Initialized
Available on crate feature uninit
only.
unsafe fn uninit_assume_init(self) -> Self::Initialized
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"));
sourceunsafe fn uninit_assume_init_one<T, I>(self) -> Self::MapReplaceOutput<T>
Available on crate feature uninit
only.
unsafe fn uninit_assume_init_one<T, I>(self) -> Self::MapReplaceOutput<T>
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;
sourceunsafe fn uninit_assume_init_read(&self) -> Self::Initializedwhere
Self: Uninit,
Available on crate feature uninit
only.
unsafe fn uninit_assume_init_read(&self) -> Self::Initializedwhere
Self: Uninit,
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);
sourceunsafe fn uninit_assume_init_read_one<T, I>(&self) -> Twhere
Self: Search<MaybeUninit<T>, I>,
Available on crate feature uninit
only.
unsafe fn uninit_assume_init_read_one<T, I>(&self) -> Twhere
Self: Search<MaybeUninit<T>, I>,
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);
sourceunsafe fn uninit_assume_init_ref(
&self,
) -> <Self::Initialized as TupleLike>::AsRefOutput<'_>where
Self: Uninit,
Available on crate feature uninit
only.
unsafe fn uninit_assume_init_ref(
&self,
) -> <Self::Initialized as TupleLike>::AsRefOutput<'_>where
Self: Uninit,
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(); }
sourceunsafe fn uninit_assume_init_ref_one<T, I>(&self) -> &Twhere
Self: Search<MaybeUninit<T>, I>,
Available on crate feature uninit
only.
unsafe fn uninit_assume_init_ref_one<T, I>(&self) -> &Twhere
Self: Search<MaybeUninit<T>, I>,
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>, _>(); }
sourceunsafe fn uninit_assume_init_mut(
&mut self,
) -> <Self::Initialized as TupleLike>::AsMutOutput<'_>where
Self: Uninit,
Available on crate feature uninit
only.
unsafe fn uninit_assume_init_mut(
&mut self,
) -> <Self::Initialized as TupleLike>::AsMutOutput<'_>where
Self: Uninit,
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]));
sourceunsafe fn uninit_assume_init_mut_one<T, I>(&mut self) -> &mut Twhere
Self: Search<MaybeUninit<T>, I>,
Available on crate feature uninit
only.
unsafe fn uninit_assume_init_mut_one<T, I>(&mut self) -> &mut Twhere
Self: Search<MaybeUninit<T>, I>,
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>, _>(); }
sourceunsafe fn uninit_assume_init_drop(&mut self)where
Self: Uninit,
Available on crate feature uninit
only.
unsafe fn uninit_assume_init_drop(&mut self)where
Self: Uninit,
uninit
only.Drop values in place for a tuple consisting of MaybeUninit
elements.
§Safety
Same as MaybeUninit::assume_init_drop()
.
sourceunsafe fn uninit_assume_init_drop_one<T, I>(&mut self)where
Self: Search<MaybeUninit<T>, I>,
Available on crate feature uninit
only.
unsafe fn uninit_assume_init_drop_one<T, I>(&mut self)where
Self: Search<MaybeUninit<T>, I>,
uninit
only.Drop value in place for a specific MaybeUninit
element.
§Safety
Same as MaybeUninit::assume_init_drop()
.
sourcefn uninit_as_ptr(&self) -> <Self::Initialized as TupleLike>::AsPtrOutputwhere
Self: Uninit,
Available on crate feature uninit
only.
fn uninit_as_ptr(&self) -> <Self::Initialized as TupleLike>::AsPtrOutputwhere
Self: Uninit,
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(); }
sourcefn uninit_as_mut_ptr(
&mut self,
) -> <Self::Initialized as TupleLike>::AsMutPtrOutputwhere
Self: Uninit,
Available on crate feature uninit
only.
fn uninit_as_mut_ptr(
&mut self,
) -> <Self::Initialized as TupleLike>::AsMutPtrOutputwhere
Self: Uninit,
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(); }
sourcefn uninit_write_one<T, I>(&mut self, value: T) -> &mut Twhere
Self: Search<MaybeUninit<T>, I>,
Available on crate feature uninit
only.
fn uninit_write_one<T, I>(&mut self, value: T) -> &mut Twhere
Self: Search<MaybeUninit<T>, I>,
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);
sourcefn uninit_write(
&mut self,
init: Self::Initialized,
) -> <Self::Initialized as TupleLike>::AsMutOutput<'_>where
Self: Uninit,
Available on crate feature uninit
only.
fn uninit_write(
&mut self,
init: Self::Initialized,
) -> <Self::Initialized as TupleLike>::AsMutOutput<'_>where
Self: Uninit,
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"));
sourceunsafe fn uninit_assume_init_subseq<Seq, I>(self) -> Self::PartiallyInitialized
Available on crate feature uninit
only.
unsafe fn uninit_assume_init_subseq<Seq, I>(self) -> Self::PartiallyInitialized
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;
sourceunsafe fn uninit_assume_init_read_subseq<Seq, I>(&self) -> Seqwhere
Seq: TupleLike,
Self: UninitSubseq<Seq, I>,
Available on crate feature uninit
only.
unsafe fn uninit_assume_init_read_subseq<Seq, I>(&self) -> Seqwhere
Seq: TupleLike,
Self: UninitSubseq<Seq, I>,
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]));
sourceunsafe 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.
unsafe fn uninit_assume_init_ref_subseq<Seq, I>(
&self,
) -> <Seq as TupleLike>::AsRefOutput<'_>where
Seq: TupleLike,
Self: UninitSubseq<Seq, I>,
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>), _>() };
sourceunsafe 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.
unsafe fn uninit_assume_init_mut_subseq<Seq, I>(
&mut self,
) -> <Seq as TupleLike>::AsMutOutput<'_>where
Seq: TupleLike,
Self: UninitSubseq<Seq, I>,
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>), _>() };
sourcefn uninit_subseq_as_ptr<Seq, I>(&self) -> <Seq as TupleLike>::AsPtrOutputwhere
Seq: TupleLike,
Self: UninitSubseq<Seq, I>,
Available on crate feature uninit
only.
fn uninit_subseq_as_ptr<Seq, I>(&self) -> <Seq as TupleLike>::AsPtrOutputwhere
Seq: TupleLike,
Self: UninitSubseq<Seq, I>,
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>), _>();
}
sourcefn uninit_subseq_as_mut_ptr<Seq, I>(
&mut self,
) -> <Seq as TupleLike>::AsMutPtrOutputwhere
Seq: TupleLike,
Self: UninitSubseq<Seq, I>,
Available on crate feature uninit
only.
fn uninit_subseq_as_mut_ptr<Seq, I>(
&mut self,
) -> <Seq as TupleLike>::AsMutPtrOutputwhere
Seq: TupleLike,
Self: UninitSubseq<Seq, I>,
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>), _>();
}
sourcefn uninit_write_subseq<Seq, I>(&mut self, subseq: Seq) -> Seq::AsMutOutput<'_>where
Seq: TupleLike,
Self: UninitSubseq<Seq, I>,
Available on crate feature uninit
only.
fn uninit_write_subseq<Seq, I>(&mut self, subseq: Seq) -> Seq::AsMutOutput<'_>where
Seq: TupleLike,
Self: UninitSubseq<Seq, I>,
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"));
sourceunsafe fn uninit_assume_init_drop_subseq<Seq, I>(&mut self)where
Seq: TupleLike,
Self: UninitSubseq<Seq, I>,
Available on crate feature uninit
only.
unsafe fn uninit_assume_init_drop_subseq<Seq, I>(&mut self)where
Seq: TupleLike,
Self: UninitSubseq<Seq, I>,
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()
.
sourceunsafe fn uninit_assume_init_con_subseq<Seq, I>(
self,
) -> Self::PartiallyInitialized
Available on crate feature uninit
only.
unsafe fn uninit_assume_init_con_subseq<Seq, I>( self, ) -> Self::PartiallyInitialized
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;
sourceunsafe fn uninit_assume_init_read_con_subseq<Seq, I>(&self) -> Seqwhere
Seq: TupleLike,
Self: UninitConSubseq<Seq, I>,
Available on crate feature uninit
only.
unsafe fn uninit_assume_init_read_con_subseq<Seq, I>(&self) -> Seqwhere
Seq: TupleLike,
Self: UninitConSubseq<Seq, I>,
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]));
sourceunsafe 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.
unsafe fn uninit_assume_init_ref_con_subseq<Seq, I>(
&self,
) -> <Seq as TupleLike>::AsRefOutput<'_>where
Seq: TupleLike,
Self: UninitConSubseq<Seq, I>,
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>), _>() };
sourceunsafe 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.
unsafe fn uninit_assume_init_mut_con_subseq<Seq, I>(
&mut self,
) -> <Seq as TupleLike>::AsMutOutput<'_>where
Seq: TupleLike,
Self: UninitConSubseq<Seq, I>,
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>), _>() };
sourcefn uninit_con_subseq_as_ptr<Seq, I>(&self) -> <Seq as TupleLike>::AsPtrOutputwhere
Seq: TupleLike,
Self: UninitConSubseq<Seq, I>,
Available on crate feature uninit
only.
fn uninit_con_subseq_as_ptr<Seq, I>(&self) -> <Seq as TupleLike>::AsPtrOutputwhere
Seq: TupleLike,
Self: UninitConSubseq<Seq, I>,
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>), _>();
}
sourcefn uninit_con_subseq_as_mut_ptr<Seq, I>(
&mut self,
) -> <Seq as TupleLike>::AsMutPtrOutputwhere
Seq: TupleLike,
Self: UninitConSubseq<Seq, I>,
Available on crate feature uninit
only.
fn uninit_con_subseq_as_mut_ptr<Seq, I>(
&mut self,
) -> <Seq as TupleLike>::AsMutPtrOutputwhere
Seq: TupleLike,
Self: UninitConSubseq<Seq, I>,
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>), _>();
}
sourcefn 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.
fn uninit_write_con_subseq<Seq, I>(
&mut self,
subseq: Seq,
) -> Seq::AsMutOutput<'_>where
Seq: TupleLike,
Self: UninitConSubseq<Seq, I>,
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"));
sourceunsafe fn uninit_assume_init_drop_con_subseq<Seq, I>(&mut self)where
Seq: TupleLike,
Self: UninitConSubseq<Seq, I>,
Available on crate feature uninit
only.
unsafe fn uninit_assume_init_drop_con_subseq<Seq, I>(&mut self)where
Seq: TupleLike,
Self: UninitConSubseq<Seq, I>,
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()
.
sourcefn untuple(self) -> Self::UntupleOutputwhere
Self: Untupleable + Sized,
fn untuple(self) -> Self::UntupleOutputwhere
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));
sourcefn flatten(self) -> Self::UntupleOutputwhere
Self: Untupleable + Sized,
fn flatten(self) -> Self::UntupleOutputwhere
Self: Untupleable + Sized,
sourcefn foreach<F>(self, mapper: F) -> <Self as Foreach<F>>::Output
fn foreach<F>(self, mapper: F) -> <Self as Foreach<F>>::Output
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()));
sourcefn fold<F, Acc>(self, folder: F, acc: Acc) -> <Self as Foldable<F, Acc>>::Output
fn fold<F, Acc>(self, folder: F, acc: Acc) -> <Self as Foldable<F, Acc>>::Output
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());
sourcefn any<Pred>(&self, predicate: Pred) -> boolwhere
Self: TestAny<Pred>,
fn any<Pred>(&self, predicate: Pred) -> boolwhere
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);
sourcefn all<Pred>(&self, predicate: Pred) -> boolwhere
Self: TestAll<Pred>,
fn all<Pred>(&self, predicate: Pred) -> boolwhere
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);
sourcefn dot<T>(self, rhs: T) -> <Self as Dot<T>>::Output
fn dot<T>(self, rhs: T) -> <Self as Dot<T>>::Output
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);
sourcefn zip2<T>(self, rhs: T) -> Self::ZipOutput2
fn zip2<T>(self, rhs: T) -> Self::ZipOutput2
sourcefn unzip(self) -> (Self::UnzipOutputLeft, Self::UnzipOutputRight)where
Self: Unzippable + Sized,
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));
sourcefn extend<T>(self, rhs: T) -> Self::ExtendBackOutputwhere
Self: Extendable<T> + Sized,
fn extend<T>(self, rhs: T) -> Self::ExtendBackOutputwhere
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))
);
sourcefn extend_front<T>(self, rhs: T) -> Self::ExtendFrontOutputwhere
Self: Extendable<T> + Sized,
fn extend_front<T>(self, rhs: T) -> Self::ExtendFrontOutputwhere
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))
);
sourcefn extend_back<T>(self, rhs: T) -> Self::ExtendBackOutputwhere
Self: Extendable<T> + Sized,
fn extend_back<T>(self, rhs: T) -> Self::ExtendBackOutputwhere
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()
.
sourcefn shrink(self) -> (Self::ShrinkBackOutput, Self::ShrinkBackElements)where
Self: Shrinkable + Sized,
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));
sourcefn shrink_front(self) -> (Self::ShrinkFrontOutput, Self::ShrinkFrontElements)where
Self: Shrinkable + Sized,
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));
sourcefn shrink_back(self) -> (Self::ShrinkBackOutput, Self::ShrinkBackElements)where
Self: Shrinkable + Sized,
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()
.
sourcefn combine<T>(self, rhs: T) -> Self::CombineOutputwhere
Self: Combinable<T> + Sized,
fn combine<T>(self, rhs: T) -> Self::CombineOutputwhere
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)));
sourcefn replace_head<T>(self, rhs: T) -> (Self::ReplaceOutput, Self::Replaced)
fn replace_head<T>(self, rhs: T) -> (Self::ReplaceOutput, Self::Replaced)
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"));
sourcefn replace_tail<T, I>(self, rhs: T) -> (Self::ReplaceOutput, Self::Replaced)
fn replace_tail<T, I>(self, rhs: T) -> (Self::ReplaceOutput, Self::Replaced)
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)));
sourcefn call<T, P>(&self, rhs: T) -> <Self as Callable<T, P>>::Outputwhere
Self: Callable<T, P>,
fn call<T, P>(&self, rhs: T) -> <Self as Callable<T, P>>::Outputwhere
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()));
sourcefn call_mut<T, P>(&mut self, rhs: T) -> <Self as MutCallable<T, P>>::Outputwhere
Self: MutCallable<T, P>,
fn call_mut<T, P>(&mut self, rhs: T) -> <Self as MutCallable<T, P>>::Outputwhere
Self: MutCallable<T, P>,
sourcefn call_once<T, P>(self, rhs: T) -> <Self as OnceCallable<T, P>>::Outputwhere
Self: OnceCallable<T, P> + Sized,
fn call_once<T, P>(self, rhs: T) -> <Self as OnceCallable<T, P>>::Outputwhere
Self: OnceCallable<T, P> + Sized,
sourcefn unwrap(self) -> Self::UnwrapOutput
Available on crate feature unwrap
only.
fn unwrap(self) -> Self::UnwrapOutput
unwrap
only.Convert from Tuple<Wrapper0<T0>, Wrapper1<T1>, ... Wrappern<Tn>>
to Tuple<T0, T1, ..., Tn>
,
when all element types Wrapper0
, Wrapper1
… Wrappern
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"));
sourcefn unwrap_or_default(self) -> Self::UnwrapOutputwhere
Self: UnwrapOrDefault + Sized,
Available on crate feature unwrap
only.
fn unwrap_or_default(self) -> Self::UnwrapOutputwhere
Self: UnwrapOrDefault + Sized,
unwrap
only.Convert from Tuple<Wrapper0<T0>, Wrapper1<T1>, ... Wrappern<Tn>>
to Tuple<T0, T1, ..., Tn>
,
when all element types Wrapper0
, Wrapper1
… Wrappern
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"));
sourcefn try_unwrap(self) -> Option<Self::UnwrapOutput>
Available on crate feature unwrap
only.
fn try_unwrap(self) -> Option<Self::UnwrapOutput>
unwrap
only.Convert from Tuple<Wrapper0<T0>, Wrapper1<T1>, ... Wrappern<Tn>>
to Option<Tuple<T0, T1, ..., Tn>>
,
when all element types Wrapper0
, Wrapper1
… Wrappern
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);