Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use super::node::Node;
- use std::fmt::{Display, Formatter, Result};
- pub struct Item<T>
- where T: Display
- {
- pub value: T,
- pub next: Node<T>,
- }
- impl<T> Item<T>
- where T: Display
- {
- pub fn new(value: T, next: Node<T>) -> Self {
- Item { value, next }
- }
- pub fn print_get_next(&self) -> Node<T> {
- let next = &self.next;
- print!("{}{}", &self, match next.value { Some(_) => ", ", None => "\n" });
- next.clone()
- }
- }
- impl<T> Display for Item<T>
- where T: Display
- {
- fn fmt(&self, f: &mut Formatter) -> Result {
- write!(f, "{}", self.value)
- }
- }
- impl<T> Drop for Item<T>
- where T: Display
- {
- fn drop(&mut self) {
- println!("Dropping item: {}", self.value);
- panic!()
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement