/// Single dependency on multiple parents.
Single dependency on multiple parents.
Single dependency on multiple parents .
pub fn bridge<P1, P2, C, F>(&mut self, constructor: F)
        where P1: 'static + Any + Send + Sync, // Parent 1
              P2: 'static + Any + Send + Sync, // Parent 2
              C: 'static + Any, // Child
              F: for<'r> Fn(&mut P1, &mut P2) -> Result<C> + 'static + Send + Sync
    {
        // Get or insert inceptor that is used to manage P1 and P2 instances.
        let inceptor_1 = match self.inceptors
            .entry((TypeId::of::<P1>(), TypeId::of::<P2>())) {
            Entry::Occupied(entry) => {
                entry.get()
                    .downcast_ref::<Arc<Mutex<Inceptor<P1, P2>>>>()
                    .expect("expected to find Inceptor of correct type in map")
                    .clone()
            }
            Entry::Vacant(entry) => {
                let arc = Arc::new(Mutex::new(if TypeId::of::<C>() == self.empty_type {
                    Inceptor::new_with_ignored_return_val(constructor)
                } else {
                    Inceptor::new_with_return_val(constructor)
                }));
                entry.insert(Box::new(arc.clone()));
                arc
            }
        };
        // Create inceptor clone for P2 instances
        let inceptor_2 = inceptor_1.clone();
        self.register_shared_constructor::<P1>(
            into_shared_constructor::<P1, P2, C>(
                inceptor_1,
                Box::new(|inceptor: &Arc<Mutex<Inceptor<P1, P2>>>, parent: &mut Box<Any>|
                {
                    let parent_for_inceptor = parent.downcast_mut::<Arc<Mutex<P1>>>()
                        .expect("expected downcast P1")
                        .clone();
                    inceptor.lock()
                        .expect("failed to lock ic1")
                        .incept_1(parent_for_inceptor)
                }),
                1
            )
        );
        self.register_shared_constructor::<P2>(
            into_shared_constructor::<P1, P2, C>(
                inceptor_2,
                Box::new(|inceptor: &Arc<Mutex<Inceptor<P1, P2>>>, parent: &mut Box<Any>|
                {
                    let parent_for_inceptor = parent.downcast_mut::<Arc<Mutex<P2>>>()
                        .expect("expected downcast P2")
                        .clone();
                    inceptor.lock()
                        .expect("failed to lock ic2")
                        .incept_2(parent_for_inceptor)
                }),
                2
            )
        );
    }
pub fn bridge < P1 , P2 , C , F > ( & mut self , constructor : F ) where P1 : ' static + Any + Send + Sync , // Parent 1 P2 : ' static + Any + Send + Sync , // Parent 2 C : ' static + Any , // Child F : for < ' r > Fn ( & mut P1 , & mut P2 ) -> Result < C > + ' static + Send + Sync { // Get or insert inceptor that is used to manage P1 and P2 instances. let inceptor_1 = match self . inceptors . entry ( ( TypeId :: of :: < P1 > ( ) , TypeId :: of :: < P2 > ( ) ) ) { Entry :: Occupied ( entry ) => { entry . get ( ) . downcast_ref :: < Arc < Mutex < Inceptor < P1 , P2 > > > > ( ) . expect ( " " ) . clone ( ) } Entry :: Vacant ( entry ) => { let arc = Arc :: new ( Mutex :: new ( if TypeId :: of :: < C > ( ) == self . empty_type { Inceptor :: new_with_ignored_return_val ( constructor ) } else { Inceptor :: new_with_return_val ( constructor ) } ) ) ; entry . insert ( Box :: new ( arc . clone ( ) ) ) ; arc } } ; // Create inceptor clone for P2 instances let inceptor_2 = inceptor_1 . clone ( ) ; self . register_shared_constructor :: < P1 > ( into_shared_constructor :: < P1 , P2 , C > ( inceptor_1 , Box :: new ( | inceptor : & Arc < Mutex < Inceptor < P1 , P2 > > > , parent : & mut Box < Any > | { let parent_for_inceptor = parent . downcast_mut :: < Arc < Mutex < P1 > > > ( ) . expect ( " " ) . clone ( ) ; inceptor . lock ( ) . expect ( " " ) . incept_1 ( parent_for_inceptor ) } ) , 1 ) ) ; self . register_shared_constructor :: < P2 > ( into_shared_constructor :: < P1 , P2 , C > ( inceptor_2 , Box :: new ( | inceptor : & Arc < Mutex < Inceptor < P1 , P2 > > > , parent : & mut Box < Any > | { let parent_for_inceptor = parent . downcast_mut :: < Arc < Mutex < P2 > > > ( ) . expect ( " " ) . clone ( ) ; inceptor . lock ( ) . expect ( " " ) . incept_2 ( parent_for_inceptor ) } ) , 2 ) ) ; }
Single dependency on multiple parents.
Single dependency on multiple parents .
&mut self
constructor
F