Advertisement
Guest User

Untitled

a guest
Aug 24th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. use std::vec::Vec;
  2. use std::rc::{Weak,Rc};
  3.  
  4. struct Component{
  5. parent: Weak<Compound>,
  6. active_site: Option< Box< ActiveSite > >,
  7. }
  8.  
  9. impl Component{
  10. fn update(&self){
  11. if self.active_site.is_some() {
  12. self.active_site.as_ref().unwrap().update(self);
  13. }
  14. }
  15. }
  16.  
  17. trait ActiveSite{
  18. fn update( &self, root: &Component);
  19. }
  20.  
  21. struct Compound{
  22. components: Vec< Rc< Component > >,
  23. }
  24.  
  25. impl Compound{
  26. /// Moves component and bind it's as part of the compound.
  27. fn addComponent(&mut self, c: Component){
  28. self.components.push(Rc::new(c));
  29. }
  30. fn removeComponent(&mut self, c: &mut Component ){
  31. self.components.remove(0);
  32. }
  33. }
  34.  
  35. #[test]
  36. fn validate(){
  37.  
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement