Guest User

Untitled

a guest
Oct 23rd, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. #[derive(Clone)]
  2. struct Nestt(Option<::std::rc::Rc<Nestt>>);
  3.  
  4. impl Nestt {
  5. pub fn depth(&self) -> usize {
  6. let mut q = ::std::borrow::Cow::Borrowed(self);
  7. let mut ctr = 0;
  8. loop {
  9. let cl = if let Some(ref x) = q.as_ref().0 {
  10. (**x).clone()
  11. } else {
  12. break;
  13. };
  14. q = ::std::borrow::Cow::Owned(cl);
  15. ctr+=1;
  16. }
  17. ctr
  18. }
  19. }
  20.  
  21. fn main() {
  22. let n = Nestt(
  23. Some(std::rc::Rc::new(Nestt(
  24. Some(std::rc::Rc::new(Nestt(
  25. None
  26. )))
  27. )))
  28. );
  29.  
  30. assert_eq!(n.depth(), 2);
  31. }
Add Comment
Please, Sign In to add comment