Skip to content

Commit 525bdfd

Browse files
committed
Impl Candidate for AsRef<str>
1 parent ceafb7f commit 525bdfd

File tree

1 file changed

+19
-34
lines changed

1 file changed

+19
-34
lines changed

src/completion.rs

Lines changed: 19 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -14,44 +14,13 @@ pub trait Candidate {
1414
fn replacement(&self) -> &str;
1515
}
1616

17-
impl Candidate for String {
17+
impl<T: AsRef<str>> Candidate for T {
1818
fn display(&self) -> &str {
19-
self.as_str()
19+
self.as_ref()
2020
}
2121

2222
fn replacement(&self) -> &str {
23-
self.as_str()
24-
}
25-
}
26-
27-
/// #[deprecated = "Unusable"]
28-
impl Candidate for str {
29-
fn display(&self) -> &str {
30-
self
31-
}
32-
33-
fn replacement(&self) -> &str {
34-
self
35-
}
36-
}
37-
38-
impl Candidate for &'_ str {
39-
fn display(&self) -> &str {
40-
self
41-
}
42-
43-
fn replacement(&self) -> &str {
44-
self
45-
}
46-
}
47-
48-
impl Candidate for Rc<str> {
49-
fn display(&self) -> &str {
50-
self
51-
}
52-
53-
fn replacement(&self) -> &str {
54-
self
23+
self.as_ref()
5524
}
5625
}
5726

@@ -647,4 +616,20 @@ mod tests {
647616
pub fn normalize() {
648617
assert_eq!(super::normalize("Windows"), "windows")
649618
}
619+
620+
#[test]
621+
pub fn candidate_impls() {
622+
struct StrCmp;
623+
impl super::Completer for StrCmp {
624+
type Candidate = &'static str;
625+
}
626+
struct RcCmp;
627+
impl super::Completer for RcCmp {
628+
type Candidate = std::rc::Rc<str>;
629+
}
630+
struct ArcCmp;
631+
impl super::Completer for ArcCmp {
632+
type Candidate = std::sync::Arc<str>;
633+
}
634+
}
650635
}

0 commit comments

Comments
 (0)