Skip to content

Commit

Permalink
Add UniCase::into_inner() and Ascii::into_inner().
Browse files Browse the repository at this point in the history
This allows retrieving the inner value for types other than &str and
String (for which Into::into() has to be used).
  • Loading branch information
Nico Madysa committed Feb 21, 2019
1 parent 0e2ad2c commit ad26bc2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/ascii.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ impl<S> Ascii<S> {
pub fn new(s: S) -> Ascii<S> {
Ascii(s)
}

#[inline]
pub fn into_inner(self) -> S {
self.0
}
}

impl<S> Deref for Ascii<S> {
Expand Down
16 changes: 12 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,17 @@ impl<S: AsRef<str>> UniCase<S> {
}
}

impl<S> UniCase<S> {
/// Unwraps the inner value held by this `UniCase`.
#[inline]
pub fn into_inner(self) -> S {
match self.0 {
Encoding::Ascii(s) => s.0,
Encoding::Unicode(s) => s.0,
}
}
}

impl<S> Deref for UniCase<S> {
type Target = S;
#[inline]
Expand Down Expand Up @@ -209,10 +220,7 @@ macro_rules! into_impl {
($to:ty) => (
impl<'a> Into<$to> for UniCase<$to> {
fn into(self) -> $to {
match self.0 {
Encoding::Ascii(Ascii(s)) => s,
Encoding::Unicode(Unicode(s)) => s,
}
self.into_inner()
}
}
);
Expand Down

0 comments on commit ad26bc2

Please sign in to comment.