Created
February 17, 2017 03:05
-
-
Save cqfd/431da2e47dc98041ca5e97ffa7f05d9f to your computer and use it in GitHub Desktop.
Spooky (empty) Rust iterable
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Spooky<T> { | |
_phantom: std::marker::PhantomData<T> | |
} | |
impl<T> Spooky<T> { | |
fn new() -> Spooky<T> { | |
Spooky { _phantom: std::marker::PhantomData } | |
} | |
} | |
struct SpookyIter<T> { | |
_phantom: std::marker::PhantomData<T> | |
} | |
impl<T> SpookyIter<T> { | |
fn new() -> SpookyIter<T> { | |
SpookyIter { _phantom: std::marker::PhantomData } | |
} | |
} | |
impl<T> Iterator for SpookyIter<T> { | |
type Item = T; | |
fn next(&mut self) -> Option<T> { | |
None | |
} | |
} | |
impl<T> IntoIterator for Spooky<T> { | |
type Item = T; | |
type IntoIter = SpookyIter<T>; | |
fn into_iter(self) -> SpookyIter<T> { | |
SpookyIter::new() | |
} | |
} | |
impl<'a, T: 'a> IntoIterator for &'a Spooky<T> { | |
type Item = &'a T; | |
type IntoIter = SpookyIter<&'a T>; | |
fn into_iter(self) -> SpookyIter<&'a T> { | |
SpookyIter::new() | |
} | |
} | |
impl<'a, T: 'a> IntoIterator for &'a mut Spooky<T> { | |
type Item = &'a mut T; | |
type IntoIter = SpookyIter<&'a mut T>; | |
fn into_iter(self) -> SpookyIter<&'a mut T> { | |
SpookyIter::new() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment