fn append_external_event(&mut self, event: ExternalEvent, line_number: &usize) {
        self.external_events.push((*line_number, event.clone()));
        
        // append_event if resource_access_point is not null
        fn maybe_append_event(vd: &mut VisualizationData, resource_access_point: &Option<ResourceAccessPoint>, event: Event, line_number : &usize) {
            if let Some(ro) = resource_access_point {
                vd._append_event(&ro, event, line_number)
            };
        }

        match event {
            // eg let ro_to = String::from("");
            ExternalEvent::Move{from: from_ro, to: to_ro} => {
                maybe_append_event(self, &to_ro, Event::Acquire{from : from_ro.to_owned()}, line_number);
                maybe_append_event(self, &from_ro, Event::Move{to : to_ro.to_owned()}, line_number);
            }
            // eg let ro_to = 5;
            ExternalEvent::Duplicate{from: from_ro, to: to_ro} => {
                maybe_append_event(self, &to_ro, Event::Acquire{from : from_ro.to_owned()}, line_number);
                maybe_append_event(self, &from_ro, Event::Duplicate{to : to_ro.to_owned()}, line_number);
            }
            ExternalEvent::StaticBorrow{from: from_ro, to: to_ro} => {
                maybe_append_event(self, &from_ro, Event::StaticLend{to : to_ro.to_owned()}, line_number);
                if let Some(some_from_ro) = from_ro {
                    maybe_append_event(self, &to_ro, Event::StaticBorrow{from : some_from_ro.to_owned()}, line_number);
                }
            }
            ExternalEvent::StaticReturn{from: from_ro, to: to_ro} => {
                maybe_append_event(self, &to_ro, Event::StaticReacquire{from : from_ro.to_owned()}, line_number);
                maybe_append_event(self, &from_ro, Event::StaticReturn{to : to_ro.to_owned()}, line_number);
            }
            ExternalEvent::MutableBorrow{from: from_ro, to: to_ro} => {
                maybe_append_event(self, &from_ro, Event::MutableLend{to : to_ro.to_owned()}, line_number);
                if let Some(some_from_ro) = from_ro {
                    maybe_append_event(self, &to_ro, Event::MutableBorrow{from : some_from_ro.to_owned()}, line_number);
                }
            }
            ExternalEvent::MutableReturn{from: from_ro, to: to_ro} => {
                maybe_append_event(self, &to_ro, Event::MutableReacquire{from : from_ro.to_owned()}, line_number);
                maybe_append_event(self, &from_ro, Event::MutableReturn{to : to_ro.to_owned()}, line_number);
            }
            // TODO do we really need to add these events, since pass by ref does not change the state?
            ExternalEvent::PassByStaticReference{from: from_ro, to: to_ro} => {
                maybe_append_event(self, &from_ro.to_owned(), Event::StaticLend{to : to_ro.to_owned()}, line_number);
                if let Some(some_from_ro) = from_ro.to_owned() {
                    maybe_append_event(self, &to_ro.to_owned(), Event::StaticBorrow{from : some_from_ro.to_owned()}, line_number);
                } else {
                    panic!("Must pass a function to PassByStaticReference.to!");
                }
                maybe_append_event(self, &from_ro, Event::StaticReacquire{from : to_ro.to_owned()}, line_number);
                maybe_append_event(self, &to_ro, Event::StaticReturn{to : from_ro.to_owned()}, line_number);
            }
            ExternalEvent::PassByMutableReference{from: from_ro, to: to_ro} => {
                maybe_append_event(self, &from_ro, Event::MutableLend{to : to_ro.to_owned()}, line_number);
                if let Some(some_from_ro) = from_ro.to_owned() {
                    maybe_append_event(self, &to_ro, Event::MutableBorrow{from : some_from_ro.to_owned()}, line_number);
                } else {
                    panic!("Must pass a function to PassByMutableReference.to!");
                }
                maybe_append_event(self, &from_ro, Event::MutableReacquire{from : to_ro.to_owned()}, line_number);
                maybe_append_event(self, &to_ro, Event::MutableReturn{to : from_ro.to_owned()}, line_number);
            }
            ExternalEvent::GoOutOfScope{ro} => {
                match ro {
                    ResourceAccessPoint::Owner(..) => {
                        maybe_append_event(self, &Some(ro), Event::OwnerGoOutOfScope, line_number);
                    },
                    ResourceAccessPoint::MutRef(..) => {
                        maybe_append_event(self, &Some(ro), Event::RefGoOutOfScope, line_number);
                    },
                    ResourceAccessPoint::StaticRef(..) => {
                        maybe_append_event(self, &Some(ro), Event::RefGoOutOfScope, line_number);
                    },
                    ResourceAccessPoint::Function(func) => {
                        println!(
                            "Functions do not go out of scope! We do not expect to see \"{}\" here.",
                            func.name
                        );
                        std::process::exit(1);
                    }
                }
            }
        }
    }
// store them in external_events, and call append_events
// default way to record events
store them in external_events, and call append_events
default way to record events
store them in external_events and call append_events default way to record events
fn append_external_event(&mut self, event: ExternalEvent, line_number: &usize) {
        self.external_events.push((*line_number, event.clone()));
        // append_event if resource_access_point is not null
        fn maybe_append_event(vd: &mut VisualizationData, resource_access_point: &Option<ResourceAccessPoint>, event: Event, line_number : &usize) {
            if let Some(ro) = resource_access_point {
                vd._append_event(&ro, event, line_number)
            };
        }
        match event {
            // eg let ro_to = String::from("");
            ExternalEvent::Move{from: from_ro, to: to_ro} => {
                maybe_append_event(self, &to_ro, Event::Acquire{from : from_ro.to_owned()}, line_number);
                maybe_append_event(self, &from_ro, Event::Move{to : to_ro.to_owned()}, line_number);
            }
            // eg let ro_to = 5;
            ExternalEvent::Duplicate{from: from_ro, to: to_ro} => {
                maybe_append_event(self, &to_ro, Event::Acquire{from : from_ro.to_owned()}, line_number);
                maybe_append_event(self, &from_ro, Event::Duplicate{to : to_ro.to_owned()}, line_number);
            }
            ExternalEvent::StaticBorrow{from: from_ro, to: to_ro} => {
                maybe_append_event(self, &from_ro, Event::StaticLend{to : to_ro.to_owned()}, line_number);
                if let Some(some_from_ro) = from_ro {
                    maybe_append_event(self, &to_ro, Event::StaticBorrow{from : some_from_ro.to_owned()}, line_number);
                }
            }
            ExternalEvent::StaticReturn{from: from_ro, to: to_ro} => {
                maybe_append_event(self, &to_ro, Event::StaticReacquire{from : from_ro.to_owned()}, line_number);
                maybe_append_event(self, &from_ro, Event::StaticReturn{to : to_ro.to_owned()}, line_number);
            }
            ExternalEvent::MutableBorrow{from: from_ro, to: to_ro} => {
                maybe_append_event(self, &from_ro, Event::MutableLend{to : to_ro.to_owned()}, line_number);
                if let Some(some_from_ro) = from_ro {
                    maybe_append_event(self, &to_ro, Event::MutableBorrow{from : some_from_ro.to_owned()}, line_number);
                }
            }
            ExternalEvent::MutableReturn{from: from_ro, to: to_ro} => {
                maybe_append_event(self, &to_ro, Event::MutableReacquire{from : from_ro.to_owned()}, line_number);
                maybe_append_event(self, &from_ro, Event::MutableReturn{to : to_ro.to_owned()}, line_number);
            }
            // TODO do we really need to add these events, since pass by ref does not change the state?
            ExternalEvent::PassByStaticReference{from: from_ro, to: to_ro} => {
                maybe_append_event(self, &from_ro.to_owned(), Event::StaticLend{to : to_ro.to_owned()}, line_number);
                if let Some(some_from_ro) = from_ro.to_owned() {
                    maybe_append_event(self, &to_ro.to_owned(), Event::StaticBorrow{from : some_from_ro.to_owned()}, line_number);
                } else {
                    panic!("Must pass a function to PassByStaticReference.to!");
                }
                maybe_append_event(self, &from_ro, Event::StaticReacquire{from : to_ro.to_owned()}, line_number);
                maybe_append_event(self, &to_ro, Event::StaticReturn{to : from_ro.to_owned()}, line_number);
            }
            ExternalEvent::PassByMutableReference{from: from_ro, to: to_ro} => {
                maybe_append_event(self, &from_ro, Event::MutableLend{to : to_ro.to_owned()}, line_number);
                if let Some(some_from_ro) = from_ro.to_owned() {
                    maybe_append_event(self, &to_ro, Event::MutableBorrow{from : some_from_ro.to_owned()}, line_number);
                } else {
                    panic!("Must pass a function to PassByMutableReference.to!");
                }
                maybe_append_event(self, &from_ro, Event::MutableReacquire{from : to_ro.to_owned()}, line_number);
                maybe_append_event(self, &to_ro, Event::MutableReturn{to : from_ro.to_owned()}, line_number);
            }
            ExternalEvent::GoOutOfScope{ro} => {
                match ro {
                    ResourceAccessPoint::Owner(..) => {
                        maybe_append_event(self, &Some(ro), Event::OwnerGoOutOfScope, line_number);
                    },
                    ResourceAccessPoint::MutRef(..) => {
                        maybe_append_event(self, &Some(ro), Event::RefGoOutOfScope, line_number);
                    },
                    ResourceAccessPoint::StaticRef(..) => {
                        maybe_append_event(self, &Some(ro), Event::RefGoOutOfScope, line_number);
                    },
                    ResourceAccessPoint::Function(func) => {
                        println!(
                            "Functions do not go out of scope! We do not expect to see \"{}\" here.",
                            func.name
                        );
                        std::process::exit(1);
                    }
                }
            }
        }
    }
fn append_external_event ( & mut self , event : ExternalEvent , line_number : & usize ) { self . external_events . push ( ( * line_number , event . clone ( ) ) ) ; // append_event if resource_access_point is not null fn maybe_append_event ( vd : & mut VisualizationData , resource_access_point : & Option < ResourceAccessPoint > , event : Event , line_number : & usize ) { if let Some ( ro ) = resource_access_point { vd . _append_event ( & ro , event , line_number ) } ; } match event { // eg let ro_to = String::from(""); ExternalEvent :: Move { from : from_ro , to : to_ro } => { maybe_append_event ( self , & to_ro , Event :: Acquire { from : from_ro . to_owned ( ) } , line_number ) ; maybe_append_event ( self , & from_ro , Event :: Move { to : to_ro . to_owned ( ) } , line_number ) ; } // eg let ro_to = 5; ExternalEvent :: Duplicate { from : from_ro , to : to_ro } => { maybe_append_event ( self , & to_ro , Event :: Acquire { from : from_ro . to_owned ( ) } , line_number ) ; maybe_append_event ( self , & from_ro , Event :: Duplicate { to : to_ro . to_owned ( ) } , line_number ) ; } ExternalEvent :: StaticBorrow { from : from_ro , to : to_ro } => { maybe_append_event ( self , & from_ro , Event :: StaticLend { to : to_ro . to_owned ( ) } , line_number ) ; if let Some ( some_from_ro ) = from_ro { maybe_append_event ( self , & to_ro , Event :: StaticBorrow { from : some_from_ro . to_owned ( ) } , line_number ) ; } } ExternalEvent :: StaticReturn { from : from_ro , to : to_ro } => { maybe_append_event ( self , & to_ro , Event :: StaticReacquire { from : from_ro . to_owned ( ) } , line_number ) ; maybe_append_event ( self , & from_ro , Event :: StaticReturn { to : to_ro . to_owned ( ) } , line_number ) ; } ExternalEvent :: MutableBorrow { from : from_ro , to : to_ro } => { maybe_append_event ( self , & from_ro , Event :: MutableLend { to : to_ro . to_owned ( ) } , line_number ) ; if let Some ( some_from_ro ) = from_ro { maybe_append_event ( self , & to_ro , Event :: MutableBorrow { from : some_from_ro . to_owned ( ) } , line_number ) ; } } ExternalEvent :: MutableReturn { from : from_ro , to : to_ro } => { maybe_append_event ( self , & to_ro , Event :: MutableReacquire { from : from_ro . to_owned ( ) } , line_number ) ; maybe_append_event ( self , & from_ro , Event :: MutableReturn { to : to_ro . to_owned ( ) } , line_number ) ; } // TODO do we really need to add these events, since pass by ref does not change the state? ExternalEvent :: PassByStaticReference { from : from_ro , to : to_ro } => { maybe_append_event ( self , & from_ro . to_owned ( ) , Event :: StaticLend { to : to_ro . to_owned ( ) } , line_number ) ; if let Some ( some_from_ro ) = from_ro . to_owned ( ) { maybe_append_event ( self , & to_ro . to_owned ( ) , Event :: StaticBorrow { from : some_from_ro . to_owned ( ) } , line_number ) ; } else { panic ! ( " " ) ; } maybe_append_event ( self , & from_ro , Event :: StaticReacquire { from : to_ro . to_owned ( ) } , line_number ) ; maybe_append_event ( self , & to_ro , Event :: StaticReturn { to : from_ro . to_owned ( ) } , line_number ) ; } ExternalEvent :: PassByMutableReference { from : from_ro , to : to_ro } => { maybe_append_event ( self , & from_ro , Event :: MutableLend { to : to_ro . to_owned ( ) } , line_number ) ; if let Some ( some_from_ro ) = from_ro . to_owned ( ) { maybe_append_event ( self , & to_ro , Event :: MutableBorrow { from : some_from_ro . to_owned ( ) } , line_number ) ; } else { panic ! ( " " ) ; } maybe_append_event ( self , & from_ro , Event :: MutableReacquire { from : to_ro . to_owned ( ) } , line_number ) ; maybe_append_event ( self , & to_ro , Event :: MutableReturn { to : from_ro . to_owned ( ) } , line_number ) ; } ExternalEvent :: GoOutOfScope { ro } => { match ro { ResourceAccessPoint :: Owner ( .. ) => { maybe_append_event ( self , & Some ( ro ) , Event :: OwnerGoOutOfScope , line_number ) ; } , ResourceAccessPoint :: MutRef ( .. ) => { maybe_append_event ( self , & Some ( ro ) , Event :: RefGoOutOfScope , line_number ) ; } , ResourceAccessPoint :: StaticRef ( .. ) => { maybe_append_event ( self , & Some ( ro ) , Event :: RefGoOutOfScope , line_number ) ; } , ResourceAccessPoint :: Function ( func ) => { println ! ( " \" \" " func name ) ; std :: process :: exit ( 1 ) ; } } } } }
store them in external_events, and call append_events
default way to record events
store them in external_events and call append_events default way to record events
&mut self
event
ExternalEvent
line_number
&usize