Skip to main content

use std : no not that std lol

use std::ops::Deref;
use std::rc::{Rc};

type Bar = Vec<u8>;

trait Foo<'a> {
    type DerefType: Deref<Target = Bar> + 'a;
    fn foo(&'a self) -> Self::DerefType;
}

struct Baz {
    v: Bar,
}

struct RefWrapper<'a, T>(&'a T);
impl<'a, T> Deref for RefWrapper<'a, T> {
    type Target = T;
   
    fn deref(&self) -> &T {
        self.0
    }
}

impl<'a> Foo<'a> for Baz {
    type DerefType = RefWrapper<'a, Bar>;

    fn foo(&'a self) -> Self::DerefType {
        RefWrapper(&self.v)
    }
}

struct Baz2 {
    v: Rc<Bar>
}

impl<'a> Foo<'a> for Baz2 {
    type DerefType = Rc<Bar>;
   
    fn foo(&'a self) -> Self::DerefType {
        self.v.clone()
    }
}


fn main(){}