Debian Codegraph @

debian/missing-sources/derive_more/tests/index_mut.rs

raw
1 #![allow(dead_code)] // some code is tested for type checking only
2
3 use derive_more::IndexMut;
4
5 #[derive(IndexMut)]
6 struct MyVec(Vec<i32>);
7 // `Index` implementation is required for `IndexMut`.
8 impl<__IdxT> ::core::ops::Index<__IdxT> for MyVec
9 where
10 Vec<i32>: ::core::ops::Index<__IdxT>,
11 {
12 type Output = <Vec<i32> as ::core::ops::Index<__IdxT>>::Output;
13 #[inline]
14 fn index(&self, idx: __IdxT) -> &Self::Output {
15 <Vec<i32> as ::core::ops::Index<__IdxT>>::index(&self.0, idx)
16 }
17 }
18
19 #[derive(IndexMut)]
20 struct Numbers {
21 #[index_mut]
22 numbers: Vec<i32>,
23 useless: bool,
24 }
25
26 // `Index` implementation is required for `IndexMut`.
27 impl<__IdxT> ::core::ops::Index<__IdxT> for Numbers
28 where
29 Vec<i32>: ::core::ops::Index<__IdxT>,
30 {
31 type Output = <Vec<i32> as ::core::ops::Index<__IdxT>>::Output;
32 #[inline]
33 fn index(&self, idx: __IdxT) -> &Self::Output {
34 <Vec<i32> as ::core::ops::Index<__IdxT>>::index(&self.numbers, idx)
35 }
36 }