diff --git a/examples/completion.rs b/examples/completion.rs index f2d1dd36..76d790be 100644 --- a/examples/completion.rs +++ b/examples/completion.rs @@ -29,10 +29,14 @@ impl Default for MyCompletion { impl Completion for MyCompletion { /// Simple completion implementation based on substring fn get(&self, input: &str) -> Option { - let s = input.to_string(); - let ss: Vec<&String> = self.options.iter().filter(|x| s == x[..s.len()]).collect(); - if ss.len() == 1 { - Some(ss[0].to_string()) + let matches = self + .options + .iter() + .filter(|option| option.starts_with(input)) + .collect::>(); + + if matches.len() == 1 { + Some(matches[0].to_string()) } else { None }