Skip to content

Commit 7b12e69

Browse files
PatrickNortontormol
authored andcommitted
Added Into impls
1 parent d49fc3b commit 7b12e69

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/ascii_string.rs

Lines changed: 24 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,12 @@ impl Into<Vec<u8>> for AsciiString {
513515
}
514516
}
515517

518+
impl Into<Vec<AsciiChar>> for AsciiString {
519+
fn into(self) -> Vec<AsciiChar> {
520+
self.vec
521+
}
522+
}
523+
516524
impl<'a> From<&'a AsciiStr> for AsciiString {
517525
#[inline]
518526
fn from(s: &'a AsciiStr) -> Self {
@@ -553,6 +561,22 @@ impl From<AsciiString> for Box<AsciiStr> {
553561
}
554562
}
555563

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

0 commit comments

Comments
 (0)