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