Basic Color support

This commit is contained in:
Jaby
2022-09-21 20:43:08 +02:00
parent 33b69823ec
commit 82000fe4e9
5 changed files with 78 additions and 7 deletions

View File

@@ -12,17 +12,21 @@ impl BitRange {
macro_rules! create_bit_functions {
($type_val:ty) => {
paste::item! {
fn [< get_mask_ $type_val >](range: &BitRange) -> $type_val {
const fn [< get_mask_ $type_val >](range: &BitRange) -> $type_val {
(1 << range.len) - 1
}
pub fn [< clear_value_ $type_val >](dst: $type_val, range: &BitRange) -> $type_val {
pub const fn [< clear_value_ $type_val >](dst: $type_val, range: &BitRange) -> $type_val {
dst & !([< get_mask_ $type_val >](range) << (range.start as $type_val))
}
pub fn [< set_value_ $type_val >](dst: $type_val, value: $type_val, range: &BitRange) -> $type_val {
pub const fn [< set_value_ $type_val >](dst: $type_val, value: $type_val, range: &BitRange) -> $type_val {
[< clear_value_ $type_val >](dst, range) | ((value & [< get_mask_ $type_val >](range)) << range.start)
}
pub const fn [< get_value_ $type_val >](src: $type_val, range: &BitRange) -> $type_val {
(src & [< get_mask_ $type_val >](range)) >> range.start
}
}
};
}