split up AutoComplete logic for testability

This commit is contained in:
Simon Gardling
2022-04-07 11:33:31 -04:00
parent 95fb39715f
commit 66c56a015a
2 changed files with 161 additions and 61 deletions

View File

@@ -41,16 +41,16 @@ pub fn generate_hint<'a>(input: &str) -> &'a HintEnum<'a> {
#[derive(Clone, PartialEq)]
pub enum HintEnum<'a> {
Single(&'static str),
Many(&'a [&'static str]),
Single(&'a str),
Many(&'a [&'a str]),
None,
}
impl std::fmt::Debug for HintEnum<'static> {
impl<'a> std::fmt::Debug for HintEnum<'a> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self) }
}
impl std::fmt::Display for HintEnum<'static> {
impl<'a> std::fmt::Display for HintEnum<'a> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
HintEnum::Single(single_data) => {
@@ -66,7 +66,7 @@ impl std::fmt::Display for HintEnum<'static> {
}
}
impl HintEnum<'static> {
impl<'a> HintEnum<'a> {
pub fn is_some(&self) -> bool { !matches!(self, HintEnum::None) }
pub fn is_none(&self) -> bool { !self.is_some() }