Trait shrimple_parser::tuple::Tuple
source · pub trait Tuple: Sized {
type Appended<NewElement>;
type Prepended<NewElement>;
type Reversed;
Show 18 methods
// Required methods
fn append<NewElement>(
self,
new_element: NewElement
) -> Self::Appended<NewElement>;
fn prepend<NewElement>(
self,
new_element: NewElement
) -> Self::Prepended<NewElement>;
fn rev(self) -> Self::Reversed;
// Provided methods
fn nth<const N: usize>(self) -> Self::Nth
where Self: IndexTuple<N> { ... }
fn nth_ref<const N: usize>(&self) -> &Self::Nth
where Self: IndexTuple<N> { ... }
fn map_nth<const N: usize, U>(
self,
f: impl FnOnce(Self::Nth) -> U
) -> Self::NthMapped<U>
where Self: IndexTuple<N> { ... }
fn first(self) -> Self::Nth
where Self: IndexTuple<0> { ... }
fn first_ref(&self) -> &Self::Nth
where Self: IndexTuple<0> { ... }
fn map_first<U>(self, f: impl FnOnce(Self::Nth) -> U) -> Self::NthMapped<U>
where Self: IndexTuple<0> { ... }
fn second(self) -> Self::Nth
where Self: IndexTuple<1> { ... }
fn second_ref(&self) -> &Self::Nth
where Self: IndexTuple<1> { ... }
fn map_second<U>(self, f: impl FnOnce(Self::Nth) -> U) -> Self::NthMapped<U>
where Self: IndexTuple<1> { ... }
fn third(self) -> Self::Nth
where Self: IndexTuple<2> { ... }
fn third_ref(&self) -> &Self::Nth
where Self: IndexTuple<2> { ... }
fn map_third<U>(self, f: impl FnOnce(Self::Nth) -> U) -> Self::NthMapped<U>
where Self: IndexTuple<2> { ... }
fn first_n<const N: usize>(self) -> Self::FirstN
where Self: SliceTuple<N> { ... }
fn strip_first_n<const N: usize>(self) -> Self::FirstNStripped
where Self: SliceTuple<N> { ... }
fn split<const N: usize>(self) -> (Self::FirstN, Self::FirstNStripped)
where Self: SliceTuple<N> { ... }
}Expand description
Trait for a generic tuple. Most methods in the trait have equivalents in the form of free-standing functions.
Required Associated Types§
Required Methods§
sourcefn append<NewElement>(
self,
new_element: NewElement
) -> Self::Appended<NewElement>
fn append<NewElement>( self, new_element: NewElement ) -> Self::Appended<NewElement>
Adds new_element to the end of the tuple.
Provided Methods§
sourcefn nth<const N: usize>(self) -> Self::Nthwhere
Self: IndexTuple<N>,
fn nth<const N: usize>(self) -> Self::Nthwhere
Self: IndexTuple<N>,
Returns the N-th element of the tuple.
For shortcuts see Tuple::first, Tuple::second, Tuple::third
sourcefn nth_ref<const N: usize>(&self) -> &Self::Nthwhere
Self: IndexTuple<N>,
fn nth_ref<const N: usize>(&self) -> &Self::Nthwhere
Self: IndexTuple<N>,
Returns a reference to the N-th element of the tuple.
For shortcuts see Tuple::first_ref, Tuple::second_ref, Tuple::third_ref
sourcefn map_nth<const N: usize, U>(
self,
f: impl FnOnce(Self::Nth) -> U
) -> Self::NthMapped<U>where
Self: IndexTuple<N>,
fn map_nth<const N: usize, U>(
self,
f: impl FnOnce(Self::Nth) -> U
) -> Self::NthMapped<U>where
Self: IndexTuple<N>,
Returns a function that transforms the N-th element of a tuple with f.
For common shortcuts, see Tuple::map_first, Tuple::map_second, Tuple::map_third
sourcefn first(self) -> Self::Nthwhere
Self: IndexTuple<0>,
fn first(self) -> Self::Nthwhere
Self: IndexTuple<0>,
Returns the first element of the tuple.
For a more generic function, see Tuple::nth
sourcefn first_ref(&self) -> &Self::Nthwhere
Self: IndexTuple<0>,
fn first_ref(&self) -> &Self::Nthwhere
Self: IndexTuple<0>,
Returns a reference to the first element of the tuple.
For a more generic function, see Tuple::nth_ref
sourcefn map_first<U>(self, f: impl FnOnce(Self::Nth) -> U) -> Self::NthMapped<U>where
Self: IndexTuple<0>,
fn map_first<U>(self, f: impl FnOnce(Self::Nth) -> U) -> Self::NthMapped<U>where
Self: IndexTuple<0>,
Transforms the first element of the tuple with f.
For a more generic function, see Tuple::map_nth
sourcefn second(self) -> Self::Nthwhere
Self: IndexTuple<1>,
fn second(self) -> Self::Nthwhere
Self: IndexTuple<1>,
Returns the second element of the tuple.
For a more generic function, see Tuple::nth
sourcefn second_ref(&self) -> &Self::Nthwhere
Self: IndexTuple<1>,
fn second_ref(&self) -> &Self::Nthwhere
Self: IndexTuple<1>,
Returns a reference to the second element of the tuple.
For a more generic function, see Tuple::nth_ref
sourcefn map_second<U>(self, f: impl FnOnce(Self::Nth) -> U) -> Self::NthMapped<U>where
Self: IndexTuple<1>,
fn map_second<U>(self, f: impl FnOnce(Self::Nth) -> U) -> Self::NthMapped<U>where
Self: IndexTuple<1>,
Transforms the second element of the tuple with f.
For a more generic function, see Tuple::map_nth
sourcefn third(self) -> Self::Nthwhere
Self: IndexTuple<2>,
fn third(self) -> Self::Nthwhere
Self: IndexTuple<2>,
Returns the third element of the tuple.
For a more generic function, see Tuple::nth
sourcefn third_ref(&self) -> &Self::Nthwhere
Self: IndexTuple<2>,
fn third_ref(&self) -> &Self::Nthwhere
Self: IndexTuple<2>,
Returns a reference to the third element of the tuple.
For a more generic function, see Tuple::nth_ref
sourcefn map_third<U>(self, f: impl FnOnce(Self::Nth) -> U) -> Self::NthMapped<U>where
Self: IndexTuple<2>,
fn map_third<U>(self, f: impl FnOnce(Self::Nth) -> U) -> Self::NthMapped<U>where
Self: IndexTuple<2>,
Transforms the third element of the tuple with f.
For a more generic function, see Tuple::map_nth
sourcefn first_n<const N: usize>(self) -> Self::FirstNwhere
Self: SliceTuple<N>,
fn first_n<const N: usize>(self) -> Self::FirstNwhere
Self: SliceTuple<N>,
Returns a tuple that containing the first N elements of the original tuple. The other elements are discarded.
sourcefn strip_first_n<const N: usize>(self) -> Self::FirstNStrippedwhere
Self: SliceTuple<N>,
fn strip_first_n<const N: usize>(self) -> Self::FirstNStrippedwhere
Self: SliceTuple<N>,
Returns the original tuple with its first N elements discarded.
Logical complement of Tuple::first_n
sourcefn split<const N: usize>(self) -> (Self::FirstN, Self::FirstNStripped)where
Self: SliceTuple<N>,
fn split<const N: usize>(self) -> (Self::FirstN, Self::FirstNStripped)where
Self: SliceTuple<N>,
Splits the tuple into one with the first N elements and one with the rest.