Re: [PATCH v8 6/7] rust: Add read_poll_timeout functions

From: FUJITA Tomonori
Date: Thu Jan 23 2025 - 02:30:15 EST


On Wed, 22 Jan 2025 21:14:00 +0100
Alice Ryhl <aliceryhl@xxxxxxxxxx> wrote:

>> > +#[track_caller]
>> > +pub fn read_poll_timeout<Op, Cond, T: Copy>(
>>
>> I wonder if we can lift the `T: Copy` restriction and have `Cond` take
>> `&T` instead. I can see this being useful in many cases.
>>
>> I know that quite often `T` is just an integer so you'd want to pass by
>> value, but I think almost always `Cond` is a very simple closure so
>> inlining would take place and they won't make a performance difference.
>
> Yeah, I think it should be
>
> Cond: FnMut(&T) -> bool,
>
> with FnMut as well.

Yeah, less restriction is better. I changed the code as follows:

#[track_caller]
pub fn read_poll_timeout<Op, Cond, T>(
mut op: Op,
mut cond: Cond,
sleep_delta: Delta,
timeout_delta: Delta,
) -> Result<T>
where
Op: FnMut() -> Result<T>,
Cond: FnMut(&T) -> bool,
{