Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::borrow::Borrow;
- use std::rc::Rc;
- struct PStackEntry<T> {
- value: T,
- down: PStack<T>,
- }
- pub struct PStack<T>(Rc<Option<PStackEntry<T>>>);
- impl<T> PStack<T> {
- pub fn iter<'a>(&'a self) -> Iter<'a, T> {
- Iter(self)
- }
- }
- pub struct Iter<'a, T>(&'a PStack<T>);
- impl<'a, T> Iterator for Iter<'a, T> {
- type Item = &'a T;
- fn next(&mut self) -> Option<Self::Item> {
- match self.0.0.borrow() {
- None => None,
- Some(entry) => {
- self.0 = &entry.down;
- Some(&entry.value)
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment