rust/tests/ui/overloaded/overloaded-autoderef-indexing.rs
2024-02-16 20:02:50 +00:00

21 lines
318 B
Rust

//@ run-pass
use std::ops::Deref;
struct DerefArray<'a, T:'a> {
inner: &'a [T]
}
impl<'a, T> Deref for DerefArray<'a, T> {
type Target = &'a [T];
fn deref<'b>(&'b self) -> &'b &'a [T] {
&self.inner
}
}
pub fn main() {
let a = &[1, 2, 3];
assert_eq!(DerefArray {inner: a}[1], 2);
}