Advertisement
tomdodd4598

Untitled

Oct 23rd, 2021
1,357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 0.71 KB | None | 0 0
  1. use super::node::Node;
  2.  
  3. use std::fmt::{Display, Formatter, Result};
  4.  
  5. pub struct Item<T>
  6.     where T: Display
  7. {
  8.     pub value: T,
  9.     pub next: Node<T>,
  10. }
  11.  
  12. impl<T> Item<T>
  13.     where T: Display
  14. {
  15.     pub fn new(value: T, next: Node<T>) -> Self {
  16.         Item { value, next }
  17.     }
  18.    
  19.     pub fn print_get_next(&self) -> Node<T> {
  20.         let next = &self.next;
  21.         print!("{}{}", &self, match next.value { Some(_) => ", ", None => "\n" });
  22.         next.clone()
  23.     }
  24. }
  25.  
  26. impl<T> Display for Item<T>
  27.     where T: Display
  28. {
  29.     fn fmt(&self, f: &mut Formatter) -> Result {
  30.         write!(f, "{}", self.value)
  31.     }
  32. }
  33.  
  34. impl<T> Drop for Item<T>
  35.     where T: Display
  36. {
  37.     fn drop(&mut self) {
  38.         println!("Dropping item: {}", self.value);
  39.         panic!()
  40.     }
  41. }
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement