1pub trait TupleGet {
5 type Output;
6
7 fn get(&self, index: usize) -> &Self::Output;
9 fn try_get(&self, index: usize) -> Option<&Self::Output>;
11}
12
13pub trait TupleGetMut: TupleGet {
15 fn get_mut(&mut self, index: usize) -> &mut Self::Output;
17 fn try_get_mut(&mut self, index: usize) -> Option<&mut Self::Output>;
19}
20
21pub trait TupleSwap: TupleGetMut {
23 fn swap(&mut self, a: usize, b: usize);
25
26 fn try_swap(&mut self, a: usize, b: usize) -> bool;
28}
29
30include!("./gen/tuple_get.rs");
31
32#[test]
33fn test() {
34 let a = (1, 2, 3, 4, 5);
35 assert_eq!(*a.get(2), 3);
36
37 let mut a = (1, 2, 3, 4, 5);
38 *a.get_mut(3) = 6;
39 assert_eq!(a, (1, 2, 3, 6, 5));
40}
41
42#[test]
43fn test_swap() {
44 let mut a = (1, 2, 3, 4, 5);
45 a.swap(1, 3);
46 assert_eq!(a, (1, 4, 3, 2, 5));
47}