2014-12-22 11:04:23 -06:00
|
|
|
use std::ops::Index;
|
|
|
|
|
2014-07-14 02:43:21 -05:00
|
|
|
struct MyVec<T> {
|
|
|
|
data: Vec<T>,
|
|
|
|
}
|
|
|
|
|
2015-01-08 05:02:42 -06:00
|
|
|
impl<T> Index<usize> for MyVec<T> {
|
2015-01-03 09:40:36 -06:00
|
|
|
type Output = T;
|
|
|
|
|
2015-03-21 20:16:57 -05:00
|
|
|
fn index(&self, i: usize) -> &T {
|
2014-10-15 01:05:01 -05:00
|
|
|
&self.data[i]
|
2014-07-14 02:43:21 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-24 19:39:40 -05:00
|
|
|
|
|
|
|
|
2014-07-14 02:43:21 -05:00
|
|
|
fn main() {
|
2021-08-24 19:39:40 -05:00
|
|
|
let v = MyVec::<Box<_>> { data: vec![Box::new(1), Box::new(2), Box::new(3)] };
|
2014-07-14 02:43:21 -05:00
|
|
|
let good = &v[0]; // Shouldn't fail here
|
|
|
|
let bad = v[0];
|
2020-09-02 02:40:56 -05:00
|
|
|
//~^ ERROR cannot move out of index of `MyVec<Box<i32>>`
|
2014-07-14 02:43:21 -05:00
|
|
|
}
|