Consolidating Vec to single anyhow::Error

⚓ Rust    📅 2026-01-03    👤 surdeus    👁️ 2      

surdeus

I have a function that returns Result<(), Vec<LibraryError>> called validate() (see here for some background).

I want to call this in my main() function that has a return type of anyhow::Result<()>.

The naive approach of ? doesn't work, because of the Vec<LibraryError> .

I tried map_err() along with format() from itertools but that is breaking things even more.

My current code is:

library_data.validate().map_err(|err_vec| 
    Err(anyhow(err_vec.into_iter().format("\n")))
   
);

I have read Idiomatic way to __collect__ errors and Error handling in a validation function but neither offered solutions to my problem.

Thanks in advance!

1 post - 1 participant

Read full topic

🏷️ Rust_feed