Messages in this thread | | | From | Miguel Ojeda <> | Date | Tue, 30 May 2023 16:13:47 +0200 | Subject | Re: [PATCH v1 6/7] rust: workqueue: add safe API to workqueue |
| |
On Tue, May 23, 2023 at 1:07 PM Alice Ryhl <aliceryhl@google.com> 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
| |