Re: [PATCH 4/4] rust: xarray: Add Guard::find() helper

Tamir Duberstein
2026-04-17T14:53:11Z

On Thu, Apr 16, 2026 at 10:17 PM Alvin Sun <alvin.sun@linux.dev> wrote:
>
>
> On 4/17/26 09:18, Matthew Wilcox wrote:
> > On Fri, Apr 17, 2026 at 09:05:54AM +0800, Alvin Sun wrote:
> >> Add a helper to find the first present entry in the XArray.
> > Why would you expose a function which does striclty less than the
> > underlying C implementation, rather than exposing all the functionality
> > that xa_find does?
> >
> >> Returns the index of the first present entry, or None if the array
> >> is empty.
> > Why not return the value found, like xa_find() does?
>
> Hi Matthew,
>
> Thanks for the feedback! I had considered both returning a tuple (key,
> &value)
> and an Entry struct, but only returned the key since that's all Tyr
> currently
> needs. I'll look at other Rust code to see which approach fits better, then
> implement it properly in v2.
>
> Best regards,
> Alvin
>
> >
> > This is all very troubling. I don't think Rust should depart from
> > what C has without good reason.
> >

More complete wrappers around the C APIs exist in Andreas'
https://lore.kernel.org/all/20260209-xarray-entry-send-v3-0-f777c65b8ae2@kernel.org/.
Perhaps we can borrow from that series?