Skip to main content

DisplayIterator

Trait DisplayIterator 

Source
pub trait DisplayIterator: Iterator + Clone
where Self::Item: Display,
{ // Provided methods fn display_concat(self) -> Concat<Self> where Self: Sized { ... } fn display_join<S>(self, sep: S) -> Join<Self, S> where Self: Sized, S: Display { ... } }
Expand description

Extension trait for iterators of Display items.

Adds display_concat() and display_join() to any iterator whose items implement Display. Both methods return lazy wrappers that themselves implement Display, so no allocation happens until someone writes the result to a formatter or calls .to_string().

§Design note

The trait requires Iterator + Clone (not IntoIterator) because Display::fmt takes &self — it cannot consume the iterator. The wrapper clones the iterator on each fmt call. For typical iterators (slice iterators, std::iter::Copied, etc.) this clone is two pointer copies — effectively free.

Provided Methods§

Source

fn display_concat(self) -> Concat<Self>
where Self: Sized,

Source

fn display_join<S>(self, sep: S) -> Join<Self, S>
where Self: Sized, S: Display,

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<I> DisplayIterator for I
where I: Iterator + Clone, I::Item: Display,