Skip to main content

generate_fixed_bit_map_struct

Macro generate_fixed_bit_map_struct 

Source
macro_rules! generate_fixed_bit_map_struct {
    (struct $name:ident<$bits:tt>) => { ... };
}
Expand description

Generate a typed bitmap wrapper struct.

This macro creates a new struct that wraps a FixedBitMap with a specific number of bits. The generated struct implements Deref and DerefMut to provide transparent access to the underlying FixedBitMap methods.

This is useful for creating type-safe bitmap wrappers with compile-time size guarantees.

§Syntax

use ranged_bitmap::generate_fixed_bit_map_struct;

generate_fixed_bit_map_struct!(struct StructName<128>);

§Arguments

  • struct $name:ident - The name of the struct to generate
  • <$bits:tt> - The number of bits the bitmap should contain

§Generated Code

The macro generates:

  • A struct wrapping FixedBitMap<BLOCKS> where BLOCKS is computed from bits
  • A new() constructor function
  • Deref and DerefMut implementations for transparent method access

§Example

use ranged_bitmap::generate_fixed_bit_map_struct;

generate_fixed_bit_map_struct!(struct MyBitmap<256>);

let mut bitmap = MyBitmap::new();
bitmap.set(10);  // Uses Deref to access FixedBitMap methods
bitmap.set_range(50, 100);

assert!(bitmap.get(10));
assert!(bitmap.check_range_is_set(50, 100));

§Performance

The generated wrapper has zero runtime overhead: all method calls are directly forwarded to the underlying FixedBitMap through deref coercion, which is optimized away by the compiler.