Skip to content

Commit 7beaf0a

Browse files
authored
Merge pull request #80 from PatrickNorton/into-rc
Added Into{Vec<AsciiChar>, Rc<AsciiStr>, Arc<AsciiStr>}
2 parents d49fc3b + 7ab5341 commit 7beaf0a

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/ascii_string.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ use std::ffi::{CStr, CString};
1515

1616
use ascii_char::AsciiChar;
1717
use ascii_str::{AsAsciiStr, AsAsciiStrError, AsciiStr};
18+
use std::rc::Rc;
19+
use std::sync::Arc;
1820

1921
/// A growable string stored as an ASCII encoded buffer.
2022
#[derive(Clone, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
@@ -513,6 +515,13 @@ impl Into<Vec<u8>> for AsciiString {
513515
}
514516
}
515517

518+
#[allow(clippy::from_over_into)]
519+
impl Into<Vec<AsciiChar>> for AsciiString {
520+
fn into(self) -> Vec<AsciiChar> {
521+
self.vec
522+
}
523+
}
524+
516525
impl<'a> From<&'a AsciiStr> for AsciiString {
517526
#[inline]
518527
fn from(s: &'a AsciiStr) -> Self {
@@ -553,6 +562,24 @@ impl From<AsciiString> for Box<AsciiStr> {
553562
}
554563
}
555564

565+
#[allow(clippy::from_over_into)]
566+
impl Into<Rc<AsciiStr>> for AsciiString {
567+
fn into(self) -> Rc<AsciiStr> {
568+
let var: Rc<[AsciiChar]> = self.vec.into();
569+
// SAFETY: AsciiStr is repr(transparent) and thus has the same layout as [AsciiChar]
570+
unsafe { Rc::from_raw(Rc::into_raw(var) as *const AsciiStr) }
571+
}
572+
}
573+
574+
#[allow(clippy::from_over_into)]
575+
impl Into<Arc<AsciiStr>> for AsciiString {
576+
fn into(self) -> Arc<AsciiStr> {
577+
let var: Arc<[AsciiChar]> = self.vec.into();
578+
// SAFETY: AsciiStr is repr(transparent) and thus has the same layout as [AsciiChar]
579+
unsafe { Arc::from_raw(Arc::into_raw(var) as *const AsciiStr) }
580+
}
581+
}
582+
556583
impl<'a> From<Cow<'a, AsciiStr>> for AsciiString {
557584
fn from(cow: Cow<'a, AsciiStr>) -> AsciiString {
558585
cow.into_owned()

0 commit comments

Comments
 (0)