Skip to content

Commit

Permalink
Impl AnsiAware for AsRef<str> instead of &str
Browse files Browse the repository at this point in the history
  • Loading branch information
mikaelmello committed Jan 4, 2024
1 parent 923047a commit d21ec46
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions inquire/src/ansi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,19 +168,29 @@ pub trait AnsiStrippable {
fn ansi_stripped_chars(&self) -> AnsiStrippedChars<'_>;
}

impl AnsiStrippable for &str {
impl<T> AnsiStrippable for T
where
T: AsRef<str>,
{
fn ansi_stripped_chars(&self) -> AnsiStrippedChars<'_> {
AnsiStrippedChars { input: self }
AnsiStrippedChars {
input: self.as_ref(),
}
}
}

pub trait AnsiAware {
fn ansi_aware_chars(&self) -> AnsiAwareChars<'_>;
}

impl AnsiAware for &str {
impl<T> AnsiAware for T
where
T: AsRef<str>,
{
fn ansi_aware_chars(&self) -> AnsiAwareChars<'_> {
AnsiAwareChars { input: self }
AnsiAwareChars {
input: self.as_ref(),
}
}
}

Expand Down

0 comments on commit d21ec46

Please sign in to comment.