Macro pub_iterator_type::pub_iterator_type
[−]
[src]
macro_rules! pub_iterator_type { ( #[$($attr:tt)*] $Name:ident [ $($NameParam:tt)* ] = $From:ty ) => { ... }; ( #[$($attr:tt)*] $Name:ident [ $($NameParam:tt)* ] = $From:ty where $($w:tt)* ) => { ... }; }
Abstract behind a tuple struct an iterator. Usefull to privatize implementation details about the implementation of the iterator. The syntax is done to be as if you write a type definition.
First you put the (non optional) doc inside #[doc="..."]
. Then
the name of your type with its generic parameter between
[]
. After =
you put the real type that should be hidden, with
an optional where
clause.
Example
// In the crate root module: #[macro_use] extern crate pub_iterator_type; // Declare the type pub_iterator_type! { #[doc="An iterator that yield infinitelly the default value."] RepeatDefault[T] = std::iter::Repeat<T> where T: Default + Clone } pub fn repeat_default<T: Default + Clone>() -> RepeatDefault<T> { RepeatDefault(std::iter::repeat(T::default())) } let iter = repeat_default::<i32>(); for i in iter.take(100) { assert_eq!(0, i); }