Trait CollectJoin
Source pub trait CollectJoin {
// Provided methods
fn join(&mut self, separator: &str) -> String
where Self: Iterator,
<Self as Iterator>::Item: ToString { ... }
fn to_vec(self) -> Vec<<Self as Iterator>::Item>
where Self: Iterator + Sized { ... }
}
Expand description
This trait provides a shortcut for two commonly used iterator adapters.
- join(…): joins ToString items into a
Vec::<String> by inserting a separator between them.
- to_vec(…): equivalent to
.collect::<Vec<_>>()
Iterator adapter that joins ToString items into a Vec::<String> by inserting separator between them.
§Example
let numbers = (0..10).filter(|&x| x < 5).join(", ");
assert_eq!(numbers, "0, 1, 2, 3, 4");
Iterator adapter that joins items into a Vec<_>; equivalent to .collect::<Vec<_>>()
§Example
let values = [1, 5, 10, 25, 50].into_iter().map(|x| x * x).to_vec();
assert_eq!(values, vec![1, 25, 100, 625, 2500]);
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.