SHARE
TWEET

Untitled

a guest May 19th, 2019 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. struct NodeUnit;
  2. struct Node<S> {
  3.     stack: S
  4. }
  5.  
  6. impl<S> Node<S> {
  7.     fn init() -> Node<()> {
  8.         Node { stack: (()) }
  9.     }
  10. }
  11.  
  12.  
  13.  
  14. impl<C, P> Node<(C, P)> {
  15.     fn push<N>(self, next: N) -> Node<(N, (C, P))> {
  16.         Node { stack: (next, self.stack) }
  17.     }
  18.    
  19.     fn peek(&self) -> &C {
  20.         &self.stack.0
  21.     }
  22.    
  23.     fn pop(self) -> Node<P> {
  24.         Node { stack: self.stack.1 }
  25.     }
  26. }
  27.  
  28. fn main() {
  29.     let n = Node::init();
  30.     /*
  31.     let n2 = n.push(0u8);
  32.     let n3 = n2.push(1u16);
  33.     println!("{}", n3.peek());
  34.    
  35.     let n2 = n3.pop();
  36.     println!("{}", n2.peek());
  37.     */
  38. }
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