Skip to content

Conversation

@winstonallo
Copy link
Owner

This trait defines the following API:

pub trait BitMap<T> {
    /// Gets the bit at position `index` from `&self`.
    fn get_bit(&self, index: u8) -> T;
    /// Sets the bit at position `index` in `&self`.
    fn set_bit(&mut self, index: u8, value: T);
    /// Gets the bits at positions `indices.start..indices.end` from `&self`.
    fn get_bits(&self, indices: Range<u8>) -> T;
    /// Sets the bits at positions `indices.start..indices.end` in `&self`.
    fn set_bits(&mut self, indices: Range<u8>, value: T);
}

Also adds a runtime assertions in bitmap structs that panics when the value passed to a setter overflows the field's bit width.

@winstonallo winstonallo changed the title Winstonallo/bitmap impl for primitive types BitMap trait for primitive types Sep 28, 2025
@winstonallo winstonallo changed the title BitMap trait for primitive types Add BitMap trait for primitive types Sep 28, 2025
@winstonallo winstonallo merged commit c739fd5 into main Sep 28, 2025
5 checks passed
@winstonallo winstonallo deleted the winstonallo/bitmap-impl-for-primitive-types branch September 28, 2025 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants