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