index_from_end/
default_implementors.rs

1use std::{
2    collections::VecDeque, 
3    ops::*
4};
5
6use crate::*;
7
8macro_rules! implement {
9    (<$($t:ident),*> $ty:ty => $o:ty) => {
10        impl <$($t),*> Index<FromEnd> for $ty {
11            type Output = $o;
12
13            fn index(&self, index: FromEnd) -> &Self::Output {
14                self.index(index.into_index(self.len()))
15            }
16        }
17
18        impl <$($t),*> IndexMut<FromEnd> for $ty {
19            fn index_mut(&mut self, index: FromEnd) -> &mut Self::Output {
20                self.index_mut(index.into_index(self.len()))
21            }
22        }
23
24        impl<$($t),*> Index<LenFrac> for $ty {
25            type Output = $o;
26        
27            fn index(&self, index: LenFrac) -> &Self::Output {
28                self.index(index.into_index(self.len()))
29            }
30        }
31
32        impl<$($t),*> IndexMut<LenFrac> for $ty {
33            fn index_mut(&mut self, index: LenFrac) -> &mut Self::Output {
34                self.index_mut(index.into_index(self.len()))
35            }
36        }
37
38        impl<$($t),*> Index<FromFrac> for $ty {
39            type Output = $o;
40        
41            fn index(&self, index: FromFrac) -> &Self::Output {
42                self.index(index.into_index(self.len()))
43            }
44        }
45
46        impl<$($t),*> IndexMut<FromFrac> for $ty {
47            fn index_mut(&mut self, index: FromFrac) -> &mut Self::Output {
48                self.index_mut(index.into_index(self.len()))
49            }
50        }
51    };
52}
53
54
55implement!{<T> [T] => T}
56implement!{<T> Vec<T> => T}
57implement!{<T> VecDeque<T> => T}
58
59
60
61
62