From ad26bc2e086ccbc919d25ddf980567e064ba9d50 Mon Sep 17 00:00:00 2001 From: Nico Madysa Date: Thu, 21 Feb 2019 22:27:58 +0100 Subject: [PATCH] Add UniCase::into_inner() and Ascii::into_inner(). This allows retrieving the inner value for types other than &str and String (for which Into::into() has to be used). --- src/ascii.rs | 5 +++++ src/lib.rs | 16 ++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/ascii.rs b/src/ascii.rs index b7a48ae..f6cf0c9 100644 --- a/src/ascii.rs +++ b/src/ascii.rs @@ -14,6 +14,11 @@ impl Ascii { pub fn new(s: S) -> Ascii { Ascii(s) } + + #[inline] + pub fn into_inner(self) -> S { + self.0 + } } impl Deref for Ascii { diff --git a/src/lib.rs b/src/lib.rs index 3f2c7c3..deb7e6c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -132,6 +132,17 @@ impl> UniCase { } } +impl UniCase { + /// 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 Deref for UniCase { type Target = S; #[inline] @@ -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() } } );