Chaining results

Let's say you're faced with:

tg.add_param("LogName", form.logname.0.clone()).unwrap();
tg.add_param("IfName", form.ifname.clone()).unwrap();
tg.add_param("RemEP", form.remep.0.to_string(MacAddressFormat::HexString))     .unwrap();

.. and you're tasked with handling these errors properly rather than just unwrap()ing, how would go you about to accomplishing this?


  • the worst case example currently has 16 such calls in succession, but that could be higher in the future; looking for a general scalable solution. (All the Result types are the same).
  • granularity isn't important (i.e. any error in this chain can be summarized as "Building parameters failed", rather than "Building Name parameter failed) -- but once one fails, there's no point in continuing.
  • The Ok case returns Ok(()).

The ? operator for the rescue.


This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.