Upgrade to bitvec 0.22 with const generics
This commit is contained in:
parent
763ef01101
commit
0d88ebe5b9
3 changed files with 17 additions and 26 deletions
|
@ -13,7 +13,7 @@ tokio = ["tokio_1", "futures-core"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
libc = "0.2.89"
|
libc = "0.2.89"
|
||||||
bitvec = "0.21"
|
bitvec = "0.22"
|
||||||
nix = "0.23"
|
nix = "0.23"
|
||||||
|
|
||||||
tokio_1 = { package = "tokio", version = "1.0", features = ["net"], optional = true }
|
tokio_1 = { package = "tokio", version = "1.0", features = ["net"], optional = true }
|
||||||
|
|
|
@ -146,34 +146,38 @@ macro_rules! evdev_enum {
|
||||||
evdev_enum!(
|
evdev_enum!(
|
||||||
$t,
|
$t,
|
||||||
Array:bitvec::BitArr!(for <$t>::COUNT, in u8),
|
Array:bitvec::BitArr!(for <$t>::COUNT, in u8),
|
||||||
|x| x,
|
|
||||||
|x| x,
|
|
||||||
bitvec::array::BitArray::as_mut_raw_slice,
|
bitvec::array::BitArray::as_mut_raw_slice,
|
||||||
bitvec::array::BitArray::zeroed,
|
bitvec::array::BitArray::zeroed(),
|
||||||
|
$($(#[$attr])* $c = $val,)*
|
||||||
|
);
|
||||||
|
};
|
||||||
|
($t:ty, box Array, $($(#[$attr:meta])* $c:ident = $val:expr,)*) => {
|
||||||
|
evdev_enum!(
|
||||||
|
$t,
|
||||||
|
Array:Box<bitvec::BitArr!(for <$t>::COUNT, in u8)>,
|
||||||
|
bitvec::array::BitArray::as_mut_raw_slice,
|
||||||
|
Box::new(bitvec::array::BitArray::zeroed()),
|
||||||
$($(#[$attr])* $c = $val,)*
|
$($(#[$attr])* $c = $val,)*
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
(
|
(
|
||||||
$t:ty,
|
$t:ty,
|
||||||
Array: $Array:ty, $arr_as_slice:expr, $arr_as_slice_mut:expr, $arr_as_buf:expr, $zero:expr,
|
Array: $Array:ty, $arr_as_buf:expr, $zero:expr,
|
||||||
$($(#[$attr:meta])* $c:ident = $val:expr,)*
|
$($(#[$attr:meta])* $c:ident = $val:expr,)*
|
||||||
) => {
|
) => {
|
||||||
impl $crate::attribute_set::ArrayedEvdevEnum for $t {
|
impl $crate::attribute_set::ArrayedEvdevEnum for $t {
|
||||||
type Array = $Array;
|
type Array = $Array;
|
||||||
fn array_as_slice(arr: &Self::Array) -> &bitvec::slice::BitSlice<bitvec::order::Lsb0, u8> {
|
fn array_as_slice(arr: &Self::Array) -> &bitvec::slice::BitSlice<bitvec::order::Lsb0, u8> {
|
||||||
let f: fn(&Self::Array) -> &bitvec::slice::BitSlice<bitvec::order::Lsb0, u8> = $arr_as_slice;
|
arr
|
||||||
f(arr)
|
|
||||||
}
|
}
|
||||||
fn array_as_slice_mut(arr: &mut Self::Array) -> &mut bitvec::slice::BitSlice<bitvec::order::Lsb0, u8> {
|
fn array_as_slice_mut(arr: &mut Self::Array) -> &mut bitvec::slice::BitSlice<bitvec::order::Lsb0, u8> {
|
||||||
let f: fn(&mut Self::Array) -> &mut bitvec::slice::BitSlice<bitvec::order::Lsb0, u8> = $arr_as_slice_mut;
|
arr
|
||||||
f(arr)
|
|
||||||
}
|
}
|
||||||
fn array_as_buf(arr: &mut Self::Array) -> &mut [u8] {
|
fn array_as_buf(arr: &mut Self::Array) -> &mut [u8] {
|
||||||
let f: fn(&mut Self::Array) -> &mut [u8] = $arr_as_buf;
|
$arr_as_buf(arr)
|
||||||
f(arr)
|
|
||||||
}
|
}
|
||||||
fn zeroed_array() -> Self::Array {
|
fn zeroed_array() -> Self::Array {
|
||||||
$zero()
|
$zero
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
evdev_enum!($t, $($(#[$attr])* $c = $val,)*);
|
evdev_enum!($t, $($(#[$attr])* $c = $val,)*);
|
||||||
|
|
|
@ -19,22 +19,9 @@ impl Key {
|
||||||
pub(crate) const COUNT: usize = libc::KEY_CNT;
|
pub(crate) const COUNT: usize = libc::KEY_CNT;
|
||||||
}
|
}
|
||||||
|
|
||||||
const fn bit_elts<T>(bits: usize) -> usize {
|
|
||||||
let width = std::mem::size_of::<T>() * 8;
|
|
||||||
bits / width + (bits % width != 0) as usize
|
|
||||||
}
|
|
||||||
// TODO: replace with BitArr!() once const generics is stable and BitView is implemented for any [T; N]
|
|
||||||
const KEY_ARRAY_LEN: usize = bit_elts::<u8>(Key::COUNT);
|
|
||||||
type KeyArray = [u8; KEY_ARRAY_LEN];
|
|
||||||
const KEY_ARRAY_INIT: KeyArray = [0; KEY_ARRAY_LEN];
|
|
||||||
|
|
||||||
evdev_enum!(
|
evdev_enum!(
|
||||||
Key,
|
Key,
|
||||||
Array: Box<[u8; KEY_ARRAY_LEN]>,
|
box Array,
|
||||||
|x| bitvec::slice::BitSlice::from_slice(&x[..]).unwrap(),
|
|
||||||
|x| bitvec::slice::BitSlice::from_slice_mut(&mut x[..]).unwrap(),
|
|
||||||
|x| &mut x[..],
|
|
||||||
|| Box::new(KEY_ARRAY_INIT),
|
|
||||||
KEY_RESERVED = 0,
|
KEY_RESERVED = 0,
|
||||||
KEY_ESC = 1,
|
KEY_ESC = 1,
|
||||||
KEY_1 = 2,
|
KEY_1 = 2,
|
||||||
|
|
Loading…
Reference in a new issue