Decorator example


#1
pub struct TopObject {
    object: MiddleObject,
}

pub struct MiddleObject {
    object: BottomObject,
}

pub struct BottomObject;

pub struct Info<'a, 'b>
    where 'b: 'a
{
    info: Option<&'a mut Info<'a, 'b>>,
}

pub trait Do {
    fn process<'a, 'b>(&mut self, info: &'a mut Info<'a, 'b>)
    where 'b: 'a;
}

impl Do for TopObject {
    fn process<'a, 'b>(&mut self, info: &'a mut Info<'a, 'b>)
        where 'b: 'a
    {
        let mut info: Info<'a, 'b> = Info { info: Some(info) };
        self.object.process(&mut info);
    }
}

impl Do for MiddleObject {
    fn process<'a, 'b>(&mut self, info: &'a mut Info<'a, 'b>)
        where 'b: 'a
    {
        let mut info = Info { info: Some(info) };
        self.object.process(&mut info);
    }
}

impl Do for BottomObject {
    fn process<'a, 'b>(&mut self, info: &'a mut Info<'a, 'b>)
        where 'b: 'a
    {
        println!("HI");
    }
}

fn main() {
    let mut top_object = TopObject { object: MiddleObject { object: BottomObject } };
    top_object.process(&mut Info { info: None });
}

Is it possible? What should I change?