Re: [PATCH v3 4/5] rust: id_pool: do not immediately acquire new ids

Danilo Krummrich
2025-10-28T19:33:33Z

On 10/28/25 11:55 AM, Alice Ryhl wrote:
> +/// Represents an unused id in an [`IdPool`].
> +pub struct UnusedId<'pool> {
> + id: usize,
> + pool: &'pool mut IdPool,
> +}
> +
> +impl<'pool> UnusedId<'pool> {
> + /// Get the unused id as an usize.
> + ///
> + /// Be aware that the id has not yet been acquired in the pool. The
> + /// [`acquire`] method must be called to prevent others from taking the id.
> + #[inline]
> + #[must_use]
> + pub fn as_usize(&self) -> usize {
> + self.id
> + }
> +
> + /// Get the unused id as an u32.
> + ///
> + /// Be aware that the id has not yet been acquired in the pool. The
> + /// [`acquire`] method must be called to prevent others from taking the id.
> + #[inline]
> + #[must_use]
> + pub fn as_u32(&self) -> u32 {
> + // CAST: The maximum possible value in an IdPool is i32::MAX.

I think this should rather be an invariant of `UnusedId`.

Reviewed-by: Danilo Krummrich <dakr@kernel.org>

> + self.id as u32
> + }