From affc9cc3203a6333d3834f826e1007b267c7f221 Mon Sep 17 00:00:00 2001 From: RustyNixieTube <49496554+RustyNixieTube@users.noreply.github.com> Date: Thu, 17 Jun 2021 23:20:54 +0200 Subject: [PATCH] Remove unsafe call in input mapper (#222) * Remove unsafe call * Run cargo fmt Co-authored-by: RustyNixieTube --- core/editor/src/input/input_mapper.rs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/core/editor/src/input/input_mapper.rs b/core/editor/src/input/input_mapper.rs index 5c2144cd..b798d6a4 100644 --- a/core/editor/src/input/input_mapper.rs +++ b/core/editor/src/input/input_mapper.rs @@ -21,7 +21,7 @@ struct MappingEntry { action: Message, } -#[derive(Debug, Clone, Default)] +#[derive(Debug, Clone)] struct KeyMappingEntries(Vec); 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() } }