Skip to content

Commit 3bdffd2

Browse files
committed
Added Into impls
1 parent 1a91033 commit 3bdffd2

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)]
@@ -474,6 +476,12 @@ impl Into<Vec<u8>> for AsciiString {
474476
}
475477
}
476478

479+
impl Into<Vec<AsciiChar>> for AsciiString {
480+
fn into(self) -> Vec<AsciiChar> {
481+
self.vec
482+
}
483+
}
484+
477485
impl<'a> From<&'a AsciiStr> for AsciiString {
478486
#[inline]
479487
fn from(s: &'a AsciiStr) -> Self {
@@ -496,6 +504,22 @@ impl Into<String> for AsciiString {
496504
}
497505
}
498506

507+
impl Into<Rc<AsciiStr>> for AsciiString {
508+
fn into(self) -> Rc<AsciiStr> {
509+
let var: Rc<[AsciiChar]> = self.vec.into();
510+
// SAFETY: AsciiStr is repr(transparent) and thus has the same layout as [AsciiChar]
511+
unsafe { Rc::from_raw(Rc::into_raw(var) as *const AsciiStr) }
512+
}
513+
}
514+
515+
impl Into<Arc<AsciiStr>> for AsciiString {
516+
fn into(self) -> Arc<AsciiStr> {
517+
let var: Arc<[AsciiChar]> = self.vec.into();
518+
// SAFETY: AsciiStr is repr(transparent) and thus has the same layout as [AsciiChar]
519+
unsafe { Arc::from_raw(Arc::into_raw(var) as *const AsciiStr) }
520+
}
521+
}
522+
499523
impl<'a> From<Cow<'a, AsciiStr>> for AsciiString {
500524
fn from(cow: Cow<'a, AsciiStr>) -> AsciiString {
501525
cow.into_owned()

0 commit comments

Comments
 (0)