Remove unsafe call in input mapper (#222)

* Remove unsafe call

* Run cargo fmt

Co-authored-by: RustyNixieTube <RustyNixieTube@users.noreply.github.com>
This commit is contained in:
RustyNixieTube 2021-06-17 23:20:54 +02:00 committed by Keavon Chambers
parent cced057459
commit affc9cc320
1 changed files with 13 additions and 6 deletions

View File

@ -21,7 +21,7 @@ struct MappingEntry {
action: Message,
}
#[derive(Debug, Clone, Default)]
#[derive(Debug, Clone)]
struct KeyMappingEntries(Vec<MappingEntry>);
impl KeyMappingEntries {
@ -38,12 +38,19 @@ impl KeyMappingEntries {
self.0.push(entry)
}
const fn new() -> Self {
Self(Vec::new())
}
fn key_array() -> [Self; NUMBER_OF_KEYS] {
let mut array: [KeyMappingEntries; NUMBER_OF_KEYS] = unsafe { std::mem::zeroed() };
for key in array.iter_mut() {
*key = KeyMappingEntries::default();
}
array
const DEFAULT: KeyMappingEntries = KeyMappingEntries::new();
[DEFAULT; NUMBER_OF_KEYS]
}
}
impl Default for KeyMappingEntries {
fn default() -> Self {
Self::new()
}
}