Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //////////////////////////////////////////
- pub struct Rec<'a> {
- pub s: Option<&'a Box<Trait1>>
- }
- impl<'a> Rec<'a> {
- pub fn new() -> Rec<'a> {
- Rec{s: None}
- }
- }
- pub trait Trait2<'a> {
- fn function_2(&self, rec: &'a mut Rec) -> bool;
- }
- /////////////////////////////////////////
- pub struct Data<'b> {
- m: &'b Box<Trait1>
- }
- impl<'b> Data<'b> {
- pub fn new(m: &'b Box<Trait1>) -> Data {
- Data { m: m }
- }
- }
- impl<'c> Trait2<'c> for Data<'c> {
- fn function_2(&self, r: &'c mut Rec) -> bool {
- r.s = Some(self.m);
- true
- }
- }
- /////////////////////////////////////////
- pub struct Struct {
- a: i32
- }
- impl Struct {
- pub fn new(a: i32) -> Struct {
- Struct{a: a}
- }
- }
- impl Trait1 for Struct {
- fn function_1(&self, rec: &Rec) -> bool {
- true
- }
- }
- ///////////////////////////////////////////
- pub struct Struct1 {
- }
- impl Struct1 {
- pub fn get_struct1(a: i32) -> Box<Trait1> {
- let struc = Struct::new(a);
- Box::new(struc)
- }
- }
- pub trait Trait1 {
- fn function_1(&self, rec: &Rec) -> bool;
- }
- ///////////////////////////////////////////
- pub struct Exec {
- e: i32
- }
- impl Exec {
- pub fn new(e: i32) -> Exec {
- Exec {e: e}
- }
- pub fn function_exec(&self, w: &Data) -> bool {
- let mut rec: Rec = Rec::new();
- w.function_2(&mut rec)
- }
- }
- //////////////////////////////////////////
- fn main() {
- let exec = Exec::new(1);
- let s_1 = Struct1::get_struct1(2);
- let data : Data = Data::new(&s_1);
- exec.function_exec(&data);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement