Re: [PATCH 2/3] rust: dma: convert the read/write macros to return Result

From: Miguel Ojeda
Date: Tue Apr 08 2025 - 09:41:16 EST


On Tue, Apr 8, 2025 at 2:40 PM Andreas Hindborg <a.hindborg@xxxxxxxxxx> wrote:
>
> But the `assert_eq!` would panic anyway if comparison fails, right?

Previously the `?` generated by the macro would return out of the
closure written by the sample, and thus it wouldn't reach the
`assert_eq!`.

Expanded:

let _ = (|| -> Result {
for (i, value) in TEST_VALUES.into_iter().enumerate() {
match (
&{
let item = ...::item_from_index(&self.ca, i)?;
unsafe { ... }
},
&value.0,
) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
...::assert_failed(...);
}
}
};
}
Ok(())
})();

Cheers,
Miguel