Skip to main content

is_valid_completion_prefix_len

Function is_valid_completion_prefix_len 

Source
pub fn is_valid_completion_prefix_len(prefix: &str) -> bool
Expand description

Checks whether prefix has an acceptable length (2 to 200 characters, inclusive) for triggering a package-name completion search.

Length is measured in Unicode scalar values (chars().count()), not bytes, so a multi-byte prefix (e.g. CJK) is bounded by how many characters the user typed rather than how many bytes those characters happen to occupy.

§Examples

assert!(!is_valid_completion_prefix_len("a")); // 1 char, too short
assert!(is_valid_completion_prefix_len("ab")); // 2 chars, accepted

// "日" is 1 char / 3 bytes: rejected despite being >= 2 bytes.
assert!(!is_valid_completion_prefix_len("日"));
// "日本" is 2 chars / 6 bytes: accepted.
assert!(is_valid_completion_prefix_len("日本"));