Skip to content

Commit

Permalink
Merge pull request #810 from gwenn/candidate
Browse files Browse the repository at this point in the history
Impl Candidate for AsRef<str>
  • Loading branch information
gwenn authored Oct 6, 2024
2 parents ceafb7f + 525bdfd commit be6f88b
Showing 1 changed file with 19 additions and 34 deletions.
53 changes: 19 additions & 34 deletions src/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,44 +14,13 @@ pub trait Candidate {
fn replacement(&self) -> &str;
}

impl Candidate for String {
impl<T: AsRef<str>> Candidate for T {
fn display(&self) -> &str {
self.as_str()
self.as_ref()
}

fn replacement(&self) -> &str {
self.as_str()
}
}

/// #[deprecated = "Unusable"]
impl Candidate for str {
fn display(&self) -> &str {
self
}

fn replacement(&self) -> &str {
self
}
}

impl Candidate for &'_ str {
fn display(&self) -> &str {
self
}

fn replacement(&self) -> &str {
self
}
}

impl Candidate for Rc<str> {
fn display(&self) -> &str {
self
}

fn replacement(&self) -> &str {
self
self.as_ref()
}
}

Expand Down Expand Up @@ -647,4 +616,20 @@ mod tests {
pub fn normalize() {
assert_eq!(super::normalize("Windows"), "windows")
}

#[test]
pub fn candidate_impls() {
struct StrCmp;
impl super::Completer for StrCmp {
type Candidate = &'static str;
}
struct RcCmp;
impl super::Completer for RcCmp {
type Candidate = std::rc::Rc<str>;
}
struct ArcCmp;
impl super::Completer for ArcCmp {
type Candidate = std::sync::Arc<str>;
}
}
}

0 comments on commit be6f88b

Please sign in to comment.