summaryrefslogtreecommitdiffstats
path: root/third_party/rust/derive_more/tests/index_mut.rs
blob: 0aba15ad52512cdeefac632bfa1b07770427c636 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#![allow(dead_code, unused_imports)]

use derive_more::IndexMut;

#[derive(IndexMut)]
struct MyVec(Vec<i32>);
//Index implementation is required for IndexMut
impl<__IdxT> ::core::ops::Index<__IdxT> for MyVec
where
    Vec<i32>: ::core::ops::Index<__IdxT>,
{
    type Output = <Vec<i32> as ::core::ops::Index<__IdxT>>::Output;
    #[inline]
    fn index(&self, idx: __IdxT) -> &Self::Output {
        <Vec<i32> as ::core::ops::Index<__IdxT>>::index(&self.0, idx)
    }
}

#[derive(IndexMut)]
struct Numbers {
    #[index_mut]
    numbers: Vec<i32>,
    useless: bool,
}

//Index implementation is required for IndexMut
impl<__IdxT> ::core::ops::Index<__IdxT> for Numbers
where
    Vec<i32>: ::core::ops::Index<__IdxT>,
{
    type Output = <Vec<i32> as ::core::ops::Index<__IdxT>>::Output;
    #[inline]
    fn index(&self, idx: __IdxT) -> &Self::Output {
        <Vec<i32> as ::core::ops::Index<__IdxT>>::index(&self.numbers, idx)
    }
}