Skip to content

Commit e946712

Browse files
committed
Implement Clone for BoxAsciiStr>
1 parent 84b6443 commit e946712

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

Diff for: src/ascii_str.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,13 @@ impl AsMut<AsciiStr> for [AsciiChar] {
452452
}
453453
}
454454

455+
#[cfg(feature = "alloc")]
456+
impl Clone for Box<AsciiStr> {
457+
fn clone(&self) -> Box<AsciiStr> {
458+
self.to_ascii_string().into()
459+
}
460+
}
461+
455462
impl<'a> From<&'a AsciiStr> for &'a [AsciiChar] {
456463
#[inline]
457464
fn from(astr: &AsciiStr) -> &[AsciiChar] {
@@ -1431,10 +1438,9 @@ mod tests {
14311438
#[test]
14321439
#[cfg(feature = "alloc")]
14331440
fn to_and_from_byte_box() {
1434-
let s = "abc".as_ascii_str().unwrap().to_ascii_string();
1435-
let boxed = s.clone().into_boxed_ascii_str();
1441+
let s = "abc".as_ascii_str().unwrap().to_ascii_string().into_boxed_ascii_str();
14361442
unsafe {
1437-
let converted = boxed.into_boxed_bytes();
1443+
let converted = s.clone().into_boxed_bytes();
14381444
assert_eq!(&converted[..], &b"abc"[..]);
14391445
let converted_back = AsciiStr::from_boxed_ascii_bytes_unchecked(converted);
14401446
assert_eq!(&converted_back[..], &s[..]);

0 commit comments

Comments
 (0)