Re: [PATCH v1 2/2] rust: Add read_poll_timeout functions

From: FUJITA Tomonori
Date: Sun Aug 17 2025 - 00:22:43 EST


On Thu, 14 Aug 2025 15:11:47 +0900 (JST)
FUJITA Tomonori <fujita.tomonori@xxxxxxxxx> wrote:

>>> +#[track_caller]
>>> +pub fn read_poll_timeout<Op, Cond, T>(
>>> + mut op: Op,
>>> + mut cond: Cond,
>>> + sleep_delta: Delta,
>>> + timeout_delta: Option<Delta>,
>>> +) -> Result<T>
>>> +where
>>> + Op: FnMut() -> Result<T>,
>>> + Cond: FnMut(&T) -> bool,
>>
>> I would consider just writing this as:
>>
>> pub fn read_poll_timeout<T>(
>> mut op: impl FnMut() -> Result<T>,
>> mut cond: impl FnMut(&T) -> bool,
>> sleep_delta: Delta,
>> timeout_delta: Option<Delta>,
>> ) -> Result<T>
>
> Surely, I'll do.

The above change caused the example code to fail to compile with a
"type annotations needed" error, so I kept the original code.


>> And I would also consider adding a new error type called TimeoutError
>> similar to BadFdError in `rust/kernel/fs/file.rs`. That way, we promise
>> to the caller that we never return error codes other than a timeout.
>
> Understood, I'll.

I was reminded that this function can return errors other than
timeout; Op closure returns an any error like register read failure.