Basically, I'm trying to make something object safe and I don't want to allocate:
use std::ops::{Deref, DerefMut};
trait Trait {}
impl Trait for i32 {}
struct View<'a>(&'a mut Wrapper<Trait + 'a>);
struct Wrapper<A: ?Sized + Trait>(A);
impl<'a> Wrapper<Trait + 'a> {
fn view<'b>(&'b mut self) -> View<'b> where 'a: 'b {
View(self as &'b mut Wrapper<Trait + 'b>)
}
}
// I shouldn't have to play this deref dance but that's another issue...
impl<'a, T: Trait + 'a> Deref for Wrapper<T> {
type Target = Wrapper<Trait + 'a>;
fn deref(&self) -> &Self::Target {
self as &Self::Target
}
}
impl<'a, T: Trait + 'a> DerefMut for Wrapper<T> {
fn deref_mut(&mut self) -> &mut Self::Target {
self as &mut Self::Target
}
}
fn dst_call(value: &mut Wrapper<Trait>) {
let _ = value.view();
}
fn main() {
let mut sized = Wrapper(0);
let _ = sized.view();
dst_call(&mut sized);
}