diff --git a/src/ascii_string.rs b/src/ascii_string.rs index e163d75..e2c1cf3 100644 --- a/src/ascii_string.rs +++ b/src/ascii_string.rs @@ -15,6 +15,8 @@ use std::ffi::{CStr, CString}; use ascii_char::AsciiChar; use ascii_str::{AsAsciiStr, AsAsciiStrError, AsciiStr}; +use std::rc::Rc; +use std::sync::Arc; /// A growable string stored as an ASCII encoded buffer. #[derive(Clone, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] @@ -513,6 +515,13 @@ impl Into> for AsciiString { } } +#[allow(clippy::from_over_into)] +impl Into> for AsciiString { + fn into(self) -> Vec { + self.vec + } +} + impl<'a> From<&'a AsciiStr> for AsciiString { #[inline] fn from(s: &'a AsciiStr) -> Self { @@ -553,6 +562,24 @@ impl From for Box { } } +#[allow(clippy::from_over_into)] +impl Into> for AsciiString { + fn into(self) -> Rc { + let var: Rc<[AsciiChar]> = self.vec.into(); + // SAFETY: AsciiStr is repr(transparent) and thus has the same layout as [AsciiChar] + unsafe { Rc::from_raw(Rc::into_raw(var) as *const AsciiStr) } + } +} + +#[allow(clippy::from_over_into)] +impl Into> for AsciiString { + fn into(self) -> Arc { + let var: Arc<[AsciiChar]> = self.vec.into(); + // SAFETY: AsciiStr is repr(transparent) and thus has the same layout as [AsciiChar] + unsafe { Arc::from_raw(Arc::into_raw(var) as *const AsciiStr) } + } +} + impl<'a> From> for AsciiString { fn from(cow: Cow<'a, AsciiStr>) -> AsciiString { cow.into_owned()