Expand description
tuple operations.
§Indexing
tuple types (with up to twelve elements) allow access to values by index, because they implement the core::ops::Index and core::ops::IndexMut traits:
use std::ops::{Index, IndexMut};
use typenum::{U0, U1, U2, U3, Len};
let tuple = ("hello", 5, true);
assert_eq!(tuple[U0::new()], "hello");
assert_eq!(tuple[U1::new()], 5);
assert_eq!(tuple[U2::new()], true);
assert_eq!(tuple.len(), U3::new());Attempting to use an out-of-bounds index is a compile-time error.
ⓘ
use std::ops::{Index, IndexMut};
use typenum::{U0, U1, U2};
let tuple = ("hello", 5, true);
assert_eq!(tuple[U0::new()], "hello"); // OK, the tuple has 3 elements
assert_eq!(tuple[U3::new()], "this is an error!");