Hi,
I'm creating my first real rust app and I am having little trouble with iterators and flat_map.
I'm creating a simple z85 encoder and decoder. Before error handling I had:
fn from_b85_chunk(data: &[u8])) -> u32;
fn to_byte_chunk(data: u32) -> Vec<u8>;
And i did
// data is a slice
data.chunks(5).map(from_b85_chunk).flat_map(to_byte_chunk).collect::<Vec<u8>>();
I want to introduce error handling so i created something like this
enum DecodeError;
fn from_b85_chunk(data: &[u8]) -> Result<u32, DecodeError>;
fn to_byte_chunk(data: u32) -> Vec<u8>;
I can now do the following:
let p = data.chunks(5).map(from_b85_chunk).collect::<Result<Vec<_>, _>>();
try!(p).iter().flat_map(to_byte_chunk).collect::<Vec<_>>()
Is there a way to do this without the collect in between from_b85_chunk and to_byte_chunk?