Re: [PATCH] rust: add bindings and API for bitmap.h and bitops.h.

From: Miguel Ojeda
Date: Thu Feb 27 2025 - 12:35:59 EST


On Thu, Feb 27, 2025 at 11:17 AM Burak Emir <bqe@xxxxxxxxxx> wrote:
>
> +use crate::bindings::{
> + bitmap_copy, bitmap_free, bitmap_zalloc, clear_bit, find_last_bit, find_next_zero_bit, set_bit,
> +};

I think it may be best to avoid importing `bindings::*` things, so
that it is clear when they happen and so that they are easier to grep
for.

I guess some of these may benefit from being inline when small
constants are involved, similar to what the C docs mention -- do we
want to have equivalents to the C "generic" ones that could be inlined
well?

> +/// * `ptr` is obtained from a successful call to bitmap_zalloc and

Please use Markdown wherever possible, e.g. `bitmap_zalloc`.

> +#[cold]
> +fn not_in_bounds_lt(arg: &'static str, len: usize, val: usize) -> ! {
> + panic!("{arg} must be less than length {len}, was {val}");
> +}

Should these be more explicit? e.g. `panic_if_not_in_bounds_lt`?

Do we want to only have infallible versions?

> +impl Bitmap {
> + /// Constructs a new Bitmap.

Please use intra-doc links where possible (and Markdown), e.g. [`Bitmap`].

> + /// Fails with AllocError if `nbits` is greater than or equal to 2^32,
> + /// or when the bitmap could not be allocated.

Some examples would be nice to add, which double as KUnit tests.

Thanks!

Cheers,
Miguel