Skip to content

Commit

Permalink
Support primitive array type
Browse files Browse the repository at this point in the history
  • Loading branch information
ken-matsui committed Dec 6, 2021
1 parent d57cf30 commit e688dec
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "suggestion"
version = "0.1.0"
version = "0.1.1"
edition = "2021"
authors = ["Ken Matsui <[email protected]>"]
description = "Provides suggestion traits for all collection types in the standard library"
Expand Down
20 changes: 20 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ macro_rules! impl_suggest_value {
};
}

// Primitive Array Type
impl<T: std::convert::AsRef<str>, const N: usize> Suggest for [T; N] {
fn suggest(&self, query: &str) -> Option<String> {
find_best_match_for_name(self.iter(), query, None)
}
}

// Sequences
impl_suggest!(LinkedList);
impl_suggest!(VecDeque);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit e688dec

Please sign in to comment.