From 831831cd1c38715edc7714ef81ebdb08c48f89e4 Mon Sep 17 00:00:00 2001 From: Soispha Date: Tue, 7 Nov 2023 19:47:35 +0100 Subject: [PATCH] refactor(keymaps): Remove dead code and duplicated module name (key) --- keymaps/Cargo.toml | 2 +- keymaps/src/error/mod.rs | 2 +- keymaps/src/key/chars/mod.rs | 28 ------------------- .../src/{key => key_repr}/key/crossterm.rs | 0 keymaps/src/{key => key_repr}/key/mod.rs | 13 +-------- .../src/{key => key_repr}/key/parsing/mod.rs | 6 ++-- .../key_representation.pest} | 0 .../chars => key_repr/key_value}/crossterm.rs | 0 .../key_value/mod.rs} | 3 ++ .../src/{key/keys.rs => key_repr/keys/mod.rs} | 2 +- keymaps/src/{key => key_repr}/mod.rs | 3 +- keymaps/src/lib.rs | 2 +- keymaps/src/trie.rs | 2 +- 13 files changed, 13 insertions(+), 50 deletions(-) delete mode 100644 keymaps/src/key/chars/mod.rs rename keymaps/src/{key => key_repr}/key/crossterm.rs (100%) rename keymaps/src/{key => key_repr}/key/mod.rs (79%) rename keymaps/src/{key => key_repr}/key/parsing/mod.rs (98%) rename keymaps/src/{key/keys.pest => key_repr/key_representation.pest} (100%) rename keymaps/src/{key/chars => key_repr/key_value}/crossterm.rs (100%) rename keymaps/src/{key/key_value.rs => key_repr/key_value/mod.rs} (99%) rename keymaps/src/{key/keys.rs => key_repr/keys/mod.rs} (98%) rename keymaps/src/{key => key_repr}/mod.rs (98%) diff --git a/keymaps/Cargo.toml b/keymaps/Cargo.toml index 2823ff6..727e3cd 100644 --- a/keymaps/Cargo.toml +++ b/keymaps/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "keymappings" +name = "keymaps" version = "0.1.0" edition = "2021" diff --git a/keymaps/src/error/mod.rs b/keymaps/src/error/mod.rs index 5b261c2..ffc4a93 100644 --- a/keymaps/src/error/mod.rs +++ b/keymaps/src/error/mod.rs @@ -2,7 +2,7 @@ use std::{fmt::Display, num::ParseIntError}; use thiserror::Error; -use crate::key::{key, keys, Keys}; +use crate::key_repr::{key, keys, Keys}; #[derive(Error, Debug)] pub enum TrieInsertError { diff --git a/keymaps/src/key/chars/mod.rs b/keymaps/src/key/chars/mod.rs deleted file mode 100644 index 63b21ed..0000000 --- a/keymaps/src/key/chars/mod.rs +++ /dev/null @@ -1,28 +0,0 @@ -#[cfg(crossterm)] -mod crossterm; - -use std::{collections::VecDeque, fmt::Display}; - -#[derive(Debug)] -pub(super) struct Chars(pub(super) VecDeque); -impl Chars { - pub(super) fn peek(&self) -> Option<&char> { - self.0.front() - } - pub(super) fn pop(&mut self) -> Option { - self.0.pop_front() - } - pub(super) fn prepend(&mut self, char_to_prepend: char) { - let mut new_vec = VecDeque::with_capacity(self.0.len() + 1); - new_vec.push_back(char_to_prepend); - new_vec.append(&mut self.0); - - self.0 = new_vec; - } -} - -impl Display for Chars { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.write_str(&self.0.iter().collect::()[..]) - } -} diff --git a/keymaps/src/key/key/crossterm.rs b/keymaps/src/key_repr/key/crossterm.rs similarity index 100% rename from keymaps/src/key/key/crossterm.rs rename to keymaps/src/key_repr/key/crossterm.rs diff --git a/keymaps/src/key/key/mod.rs b/keymaps/src/key_repr/key/mod.rs similarity index 79% rename from keymaps/src/key/key/mod.rs rename to keymaps/src/key_repr/key/mod.rs index 1f07255..1580ba9 100644 --- a/keymaps/src/key/key/mod.rs +++ b/keymaps/src/key_repr/key/mod.rs @@ -9,7 +9,7 @@ use pest_derive::Parser; use super::KeyValue; #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, Default, Parser)] -#[grammar = "./key/keys.pest"] +#[grammar = "./key_repr/key_representation.pest"] pub struct Key { // Modifiers pub(super) alt: bool, @@ -60,17 +60,6 @@ impl Key { } output } - - fn merge_with(mut self, other: Key) -> Self { - // Modifiers - self.alt = self.alt || other.alt; - self.ctrl = self.ctrl || other.ctrl; - self.meta = self.meta || other.meta; - self.shift = self.shift || other.shift; - - self.value = Some(self.value.unwrap_or(other.value.unwrap_or(KeyValue::Null))); - self - } } impl Display for Key { diff --git a/keymaps/src/key/key/parsing/mod.rs b/keymaps/src/key_repr/key/parsing/mod.rs similarity index 98% rename from keymaps/src/key/key/parsing/mod.rs rename to keymaps/src/key_repr/key/parsing/mod.rs index dfc1b05..5d6b14a 100644 --- a/keymaps/src/key/key/parsing/mod.rs +++ b/keymaps/src/key_repr/key/parsing/mod.rs @@ -1,10 +1,10 @@ -use std::{fmt::Debug, hash::Hash, marker, mem, str::FromStr}; +use std::{fmt::Debug, hash::Hash, marker, str::FromStr}; use pest::{iterators::Pair, Parser}; -use crate::{error, key::KeyValue}; +use crate::{error, key_repr::{KeyValue, key::Rule}}; -use super::{Key, Rule}; +use super::Key; impl Key { pub fn from_pair(pair: Pair) -> Self diff --git a/keymaps/src/key/keys.pest b/keymaps/src/key_repr/key_representation.pest similarity index 100% rename from keymaps/src/key/keys.pest rename to keymaps/src/key_repr/key_representation.pest diff --git a/keymaps/src/key/chars/crossterm.rs b/keymaps/src/key_repr/key_value/crossterm.rs similarity index 100% rename from keymaps/src/key/chars/crossterm.rs rename to keymaps/src/key_repr/key_value/crossterm.rs diff --git a/keymaps/src/key/key_value.rs b/keymaps/src/key_repr/key_value/mod.rs similarity index 99% rename from keymaps/src/key/key_value.rs rename to keymaps/src/key_repr/key_value/mod.rs index 72d3c32..cd3b57e 100644 --- a/keymaps/src/key/key_value.rs +++ b/keymaps/src/key_repr/key_value/mod.rs @@ -1,3 +1,6 @@ +#[cfg(crossterm)] +mod crossterm; + use std::{ fmt::{Display, Write}, str::FromStr, diff --git a/keymaps/src/key/keys.rs b/keymaps/src/key_repr/keys/mod.rs similarity index 98% rename from keymaps/src/key/keys.rs rename to keymaps/src/key_repr/keys/mod.rs index 1eabe12..d69039a 100644 --- a/keymaps/src/key/keys.rs +++ b/keymaps/src/key_repr/keys/mod.rs @@ -8,7 +8,7 @@ use super::Key; use std::{fmt::Display, str::FromStr}; #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Default, Parser)] -#[grammar = "./key/keys.pest"] +#[grammar = "./key_repr/key_representation.pest"] pub struct Keys(pub(super) Vec); impl Keys { diff --git a/keymaps/src/key/mod.rs b/keymaps/src/key_repr/mod.rs similarity index 98% rename from keymaps/src/key/mod.rs rename to keymaps/src/key_repr/mod.rs index 44d3a2b..925038e 100644 --- a/keymaps/src/key/mod.rs +++ b/keymaps/src/key_repr/mod.rs @@ -1,4 +1,3 @@ -pub mod chars; pub mod key; pub mod key_value; pub mod keys; @@ -9,7 +8,7 @@ pub use keys::Keys; #[cfg(test)] mod test { - use crate::key::{Key, KeyValue}; + use crate::key_repr::{Key, KeyValue}; use pretty_assertions::assert_eq; use super::Keys; diff --git a/keymaps/src/lib.rs b/keymaps/src/lib.rs index 6c1d071..ab1be33 100644 --- a/keymaps/src/lib.rs +++ b/keymaps/src/lib.rs @@ -1,3 +1,3 @@ -pub mod key; +pub mod key_repr; pub mod trie; pub mod error; diff --git a/keymaps/src/trie.rs b/keymaps/src/trie.rs index 5b65ec9..5012422 100644 --- a/keymaps/src/trie.rs +++ b/keymaps/src/trie.rs @@ -4,7 +4,7 @@ use log::info; use crate::error; -use super::key::{Key, Keys}; +use super::key_repr::{Key, Keys}; #[derive(Debug, PartialEq, Eq)] pub struct Node> {