Re: [PATCH v1 6/7] rust: workqueue: add safe API to workqueue
From: Miguel Ojeda
Date: Tue May 30 2023 - 10:14:36 EST
On Tue, May 23, 2023 at 1:07 PM Alice Ryhl <aliceryhl@xxxxxxxxxx> wrote:
>
> I think this is a question of style. For a comparison:
>
> match (queue_work_on)(work_ptr) {
> true => Ok(()),
> // SAFETY: The work queue has not taken ownership of the pointer.
> false => Err(unsafe { Arc::from_raw(ptr) }),
> }
>
> vs
>
> if (queue_work_on)(work_ptr) {
> Ok(())
> } else {
> // SAFETY: The work queue has not taken ownership of the pointer.
> Err(unsafe { Arc::from_raw(ptr) }),
> }
There is also the possibility of using the early return style:
if ... {
return Err(...);
}
Ok(())
This one makes it consistent with other early exits (i.e. whether at
the end of the function or not) and closer to the C side.
It is particularly nice when we are talking about errors, instead of
two "equal", non-error outcomes.
Cheers,
Miguel