macro_rules! take { ($($t:tt)*) => { ... }; }
Expand description
Take the element at a specific index of the tuple and get the remainder.
When the type of element is provided instead of its index, this macro expands to
take()
.
The pop()
and pop_front()
methods
also provide ways to pop elements from the front or back of the tuple.
§Syntax
-
take!(Expr; Index)
The index must be an integer literal since procedural macros do not yet support evaluating constants.
-
take!(Expr; Type)
There is currently a restriction: only one element in the tuple can be of the type being searched.
§Examples
Use indices:
use tuplez::{take, tuple};
let tup = tuple!(1, "hello", 3.14, [1, 2, 3]);
let (element, remainder) = take!(tup; 2);
assert_eq!(element, 3.14);
assert_eq!(remainder, tuple!(1, "hello", [1, 2, 3]));
let tup = tuple!(1);
let (element, remainder) = take!(tup; 0);
assert_eq!(element, 1);
assert_eq!(remainder, tuple!());
Use types:
use tuplez::{take, tuple};
let tup = tuple!(1, "hello", 3.14, [1, 2, 3]);
let (element, remainder) = take!(tup; &str);
assert_eq!(element, "hello");
assert_eq!(remainder, tuple!(1, 3.14, [1, 2, 3]));
let tup = tuple!(1);
let (element, remainder) = take!(tup; i32);
assert_eq!(element, 1);
assert_eq!(remainder, tuple!());