From e688dec7d5f575b8b5d722774d350d86fbc38453 Mon Sep 17 00:00:00 2001 From: Ken Matsui <26405363+ken-matsui@users.noreply.github.com> Date: Tue, 7 Dec 2021 05:25:13 +0900 Subject: [PATCH] Support primitive array type --- Cargo.toml | 2 +- src/lib.rs | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index c5af687..04a64e3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "suggestion" -version = "0.1.0" +version = "0.1.1" edition = "2021" authors = ["Ken Matsui <26405363+ken-matsui@users.noreply.github.com>"] description = "Provides suggestion traits for all collection types in the standard library" diff --git a/src/lib.rs b/src/lib.rs index b5a4b24..35666d2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -80,6 +80,13 @@ macro_rules! impl_suggest_value { }; } +// Primitive Array Type +impl, const N: usize> Suggest for [T; N] { + fn suggest(&self, query: &str) -> Option { + find_best_match_for_name(self.iter(), query, None) + } +} + // Sequences impl_suggest!(LinkedList); impl_suggest!(VecDeque); @@ -126,6 +133,19 @@ mod tests { }; } + // Primitive Array Type + #[test] + fn test_array() { + let input = ["aaab", "aaabc"]; + assert_eq!(input.suggest("aaaa"), Some("aaab".to_string())); + + let ref input = ["aaab", "aaabc"]; + assert_eq!(input.suggest("aaaa"), Some("aaab".to_string())); + + let ref mut input = ["aaab", "aaabc"]; + assert_eq!(input.suggest("aaaa"), Some("aaab".to_string())); + } + // Sequences test_suggest!(LinkedList, test_suggest_linked_list); test_suggest!(VecDeque, test_suggest_vec_deque);