Expand description
Utility library to work with tuples.
§Features:
-
Test if all elements are Ok: all_ok()
features = ["all-ok"]
, included by defaultassert_eq!( all_ok((good(1), good(2), good(3))), Ok((1, 2, 3)), ); assert_eq!( all_ok((good(1), bad(2), good(3))), Err((Ok(1), Err(2), Ok(3))) );
-
Test if all elements are Some: all_some()
features = ["all-some"]
, included by defaultassert_eq!( all_some((Some(1), Some(2), Some(3))), Ok((1, 2, 3)) ); assert_eq!( all_some((Some(1), Option::<()>::None, Some(3))), Err((Some(1), None, Some(3))) );
-
Prepend an element to a tuple: prepend()
features = ["prepend"]
, included by defaultassert_eq!(prepend(1, (2, 3, 4)), (1, 2, 3, 4));
-
Append an element to a tuple: append()
features = ["append"]
, included by defaultassert_eq!(append((1, 2, 3), 4), (1, 2, 3, 4));
-
Concatenate two tuples: concat_tuples()
features = ["concat"]
, included by defaultassert_eq!(concat_tuples((1, 2), (3, 4, 5)), (1, 2, 3, 4, 5));
-
Concatenate multiple tuples: concat_many()
features = ["concat-many"]
, included by defaultassert_eq!(concat_many(((), (1,), (2, 3,), (4, 5, 6))), (1, 2, 3, 4, 5, 6));
-
Turn a reference to a tuple to a tuple of references: ref_tuple()
features = ["ref"]
, included by defaultassert_eq!(ref_tuple(&(1, 2, 3)), (&1, &2, &3));
-
Turn a reference to a mutable tuple to a tuple of mutable references: ref_mut_tuple()
features = ["ref-mut"]
, included by defaultassert_eq!(ref_mut_tuple(&mut (1, 2, 3)), (&mut 1, &mut 2, &mut 3));
-
Extract the first element of a tuple: unprepend()
features = ["unprepend"]
, included by defaultassert_eq!(unprepend((1, 2, 3, 4)), (1, (2, 3, 4)));
-
Extract the last element of a tuple: unappend()
features = ["unappend"]
, included by defaultassert_eq!(unappend((1, 2, 3, 4)), ((1, 2, 3), 4));
-
Call a function with the tuple members as arguments: apply()
features = ["apply"]
, included by defaultfn add3(a: u32, b: u32, c: u32) -> u32 { a + b + c } let tpl3 = (1, 2, 3); assert_eq!(apply(&add3, tpl3), 6);
-
Element-wise wrap the element of a tuple in Option: option_tuple()
features = ["option"]
, included by defaultassert_eq!(option_tuple(Some((1, 2, 3))), (Some(1), Some(2), Some(3)));
-
Get the length of a tuple: length()
features = ["length"]
, included by defaultassert_eq!(<(u8, u16, u32) as TupleLength>::LENGTH, 3);
-
Map a tuple: map_tuple()
features = ["[map](map_tuple)"]
, not included by default, because it needs the unstable featuregeneric_associated_types
(GAT).struct MyTupleEnum(usize); impl TupleMapper for MyTupleEnum { type MapElem<Type> = (usize, Type); fn map_elem<Elem>(&mut self, elem: Elem) -> Self::MapElem<Elem> { let index = self.0; self.0 += 1; (index, elem) } } assert_eq!( map_tuple(MyTupleEnum(1), ("hello", "world", "!")), ((1, "hello"), (2, "world"), (3, "!")), )
When used in libraries, you should probably use default-features = false
, and only opt in
to the features you actually need.
§Supported tuple lengths:
By default the selected operations are implemented to tuples upto a length of 16 elements
(features = ["default-len"]
).
You can specify a higher limit by using feature = ["X"]
, where X can be
8, 16, 32, 64, 96, 128, 160, 192, 224, or 256. A higher number includes all lower numbers.
Beware: features = ["256"]
needs about 5 GB of RAM to compile the module,
so only use it if you actually need it.
Traits§
- Tuple
tuple
- A tuple.
- Tuple
AllOk all-ok
- A tuple that is usable with all_ok().
- Tuple
AllSome all-some
- A tuple that is usable with all_some().
- Tuple
Append append
- A tuple and an element that are usable with append().
- Tuple
Apply apply
- A function and a tuple that are usable with apply().
- Tuple
Concat concat
- Two tuples that are usable with concat_tuples().
- Tuple
Concat Many concat-many
- A tuple of tuples that is usable with concat_many().
- Tuple
Length length
- A tuple with a known length.
- Tuple
Map map
- A TupleMapper and a tuple that are usable with map_tuple().
- Tuple
Mapper map
- Helper trait to element-wise map a tuple.
- Tuple
Option option
- A tuple that is usable with option_tuple().
- Tuple
Prepend prepend
- An element and a tuple that are usable with prepend().
- Tuple
Ref ref
- A reference to a tuple that is usable with ref_tuple().
- Tuple
RefMut ref-mut
- A reference to a mutable tuple that is usable with ref_mut_tuple().
- Tuple
Unappend unappend
- A tuple that is usable with unappend().
- Tuple
Unprepend unprepend
- A tuple that is usable with unprepend().
Functions§
- all_ok
all-ok
- Element-wise unwrap a tuple of Results if all elements are good. Return the input otherwise.
- all_
some all-some
- Element-wise unwrap a tuple of Options if all elements are good. Return the input otherwise.
- append
append
- Append an element to a tuple.
- apply
apply
- Call a function with the tuples members as arguments.
- concat_
many concat-many
- Concatenate two or more tuples.
- concat_
tuples concat
- Concatenate two tuples.
- length
length
andfeature-const_fn_trait_bound
- Return the length of a tuple.
- map_
tuple map
- Element-wise map a tuple with a mapper.
- option_
tuple option
- Element-wise wrap the element of a tuple in Option.
- prepend
prepend
- Prepend an elemenent to a tuple.
- ref_
mut_ tuple ref-mut
- Turn a reference to a mutable tuple into a tuple of mutable references.
- ref_
tuple ref
- Turn a reference to a tuple into a tuple of references.
- unappend
unappend
- Extract the last element of a tuple, and return a tuple of the initial tuple and the last element.
- unprepend
unprepend
- Extract the first element of a tuple, and return a tuple of the first element and the last elements of the tuple.
Type Aliases§
- AllOk
all-ok
- The type when a tuple of Results is element-wise unwrapped.
- AllSome
all-some
- The type when a tuple of Options is element-wise unwrapped.
- Append
append
- The resulting type when an element is appended to an initial tuple.
- Apply
apply
- The resulting type when F is called with Tpl’s elements.
- Concat
Many concat-many
- The resulting type when two or more tuples are concatenated.
- Concat
Tuples concat
- The resulting type when two tuples are concatenated.
- Head
unprepend
- The type of the first element of the tuple.
- Init
unappend
- The resulting tuple when the last element is removed from a tuple.
- Last
unappend
- The type of the last element of the tuple.
- MapTuple
- The type of a tuple when element-wise mapped with a mapper.
- Option
Tuple option
- The resulting tuple when all elements are wrapped in Option.
- Prepend
prepend
- The resulting type when an element is prepended to a tuple.
- RefMut
Tuple ref-mut
- The resulting type when every element of this reference to a mutable tuple is turned into a mutable reference.
- RefTuple
ref
- The resulting type when every element of this reference to a tuple is turned into a reference.
- Tail
unprepend
- The resulting tuple when the first element is removed from a tuple.