lkml.org 
[lkml]   [2023]   [May]   [30]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [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

\
 
 \ /
  Last update: 2023-05-30 16:15    [W:0.113 / U:1.508 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site