pub trait TupleLike {
type AsRefOutput<'a>: TupleLike
where Self: 'a;
type AsMutOutput<'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;
const LEN: usize;
// Required methods
fn as_ref(&self) -> Self::AsRefOutput<'_>;
fn as_mut(&mut self) -> Self::AsMutOutput<'_>;
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>;
// Provided method
fn len(&self) -> usize { ... }
}Expand description
The TupleLike trait defines the basic methods of tuples.
Notice that an Unit contains no elements and cannot be popped, so the pop methods is not required methods of a tuple.
See the Popable trait about pop methods.
In fact, all tuples implement the rotation methods.
However, since right rotation requires additional detection of whether the tuple can be popped,
and cannot be introduced into TupleLike in a elegant way, so an extra trait Rotatable is used for them.
Another thing is, due to the limitation that Rust cannot 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 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.
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::*;
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::*;
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 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::*;
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::*;
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::*;
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::*;
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 a tuple!(a, b, c ...) to tuple!(Some(a), Some(b), Some(c) ...).
§Example
use tuplez::*;
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 a tuple!(a, b, c ...) to tuple!(Ok(a), Ok(b), Ok(c) ...).
Note: You need to provide the error type.
§Example
use tuplez::*;
let tup = tuple!(1, "hello", 3.14);
assert_eq!(tup.to_ok::<()>(), tuple!(Ok(1), Ok("hello"), Ok(3.14)));