From 7b12e696b09281b408da1dbbb6a9223695fe619c Mon Sep 17 00:00:00 2001 From: Patrick Norton Date: Sun, 24 Jan 2021 07:38:42 -0500 Subject: [PATCH 1/2] Added Into impls --- src/ascii_string.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/ascii_string.rs b/src/ascii_string.rs index e163d75..115cd3a 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,12 @@ impl Into> for AsciiString { } } +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 +561,22 @@ impl From for Box { } } +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) } + } +} + +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() From 7ab5341097202e7cefdc77b8a22ed27268e2a145 Mon Sep 17 00:00:00 2001 From: tormol Date: Thu, 9 Jun 2022 21:59:55 +0200 Subject: [PATCH 2/2] Slience new clippy lints --- src/ascii_string.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/ascii_string.rs b/src/ascii_string.rs index 115cd3a..e2c1cf3 100644 --- a/src/ascii_string.rs +++ b/src/ascii_string.rs @@ -515,6 +515,7 @@ impl Into> for AsciiString { } } +#[allow(clippy::from_over_into)] impl Into> for AsciiString { fn into(self) -> Vec { self.vec @@ -561,6 +562,7 @@ impl From for Box { } } +#[allow(clippy::from_over_into)] impl Into> for AsciiString { fn into(self) -> Rc { let var: Rc<[AsciiChar]> = self.vec.into(); @@ -569,6 +571,7 @@ impl Into> for AsciiString { } } +#[allow(clippy::from_over_into)] impl Into> for AsciiString { fn into(self) -> Arc { let var: Arc<[AsciiChar]> = self.vec.into();