daily pastebin goal
14%
SHARE
TWEET

Untitled

a guest Oct 23rd, 2018 77 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top