Guest User

Untitled

a guest
Jan 19th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. #![allow(unused)]
  2.  
  3. use std::rc::Rc;
  4. use std::path::PathBuf;
  5.  
  6. trait HasNew {
  7. fn new() -> Self;
  8. fn x(&self) -> Self;
  9. fn y(&self) -> Vec<Rc<Self>> where Self : Sized;
  10. }
  11.  
  12. pub trait TreeNode
  13. {
  14. fn children(&self) -> Rc<Self>;
  15. }
  16.  
  17. struct X {
  18. x : u16
  19. }
  20.  
  21. impl X {
  22. fn new() -> Self {
  23. X { x : 8 }
  24. }
  25. }
  26.  
  27. impl TreeNode for X {
  28. fn children(&self) -> Rc<Self> {
  29. Rc::new(X::new())
  30. }
  31. }
  32.  
  33. impl HasNew for u16{
  34. fn new() -> u16 {
  35. return 16;
  36. }
  37.  
  38. fn x(&self) -> u16 {
  39. 2 + 2
  40. }
  41.  
  42. fn y(&self) -> Vec<Rc<u16>> {
  43. vec![Rc::new(2)]
  44. }
  45. }
  46.  
  47. fn returns_t<T: HasNew>() -> T {
  48. return T::new();
  49. }
  50.  
  51. fn main() {
  52. let u: u16 = returns_t();
  53.  
  54. let t : Rc<TreeNode> = X::new().children();
  55.  
  56. println!("u={}", u);
  57. }
Add Comment
Please, Sign In to add comment