Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Impl Candidate for AsRef<str> #810

Merged
merged 1 commit into from
Oct 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>;
}
}
}