I want to take "hello world" and print each two consecutive characters on a new line.
The compilation fails with:
--> src/main.rs:55:14
|
55 | .map(|c| String::from(c))
| ^^^
|
= note: the method `map` exists but the following trait bounds were not satisfied:
`&mut itertools::IntoChunks<std::str::Chars<'_>> : std::iter::Iterator`
The error message is saying that IntoChunks is not an Iterator. Sometimes it could be because your type parameter doesn't meet some constraint, but in this case it's universal. The docs say:
IntoChunks is based on GroupBy : it is iterable (implements IntoIterator , notIterator ), and it only buffers if several chunk iterators are alive at the same time.
This is a matter of getting the ownership and lifetimes right, but you can call .into_iter() to iterate from there.
Then you'll find that String::from(c) doesn't work with the Chunk items. That type is an Iterator though, so you could collect() or use String::from_iter(c). Or even fancier, use c.format("") to create a dynamic Format item which will be displayed by the join("\n").