Skip to content

Commit 9dca934

Browse files
committed
Implement Clone for BoxAsciiStr>
1 parent c9c55dc commit 9dca934

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/ascii_str.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,13 @@ impl AsMut<AsciiStr> for [AsciiChar] {
514514
}
515515
}
516516

517+
#[cfg(feature = "alloc")]
518+
impl Clone for Box<AsciiStr> {
519+
fn clone(&self) -> Box<AsciiStr> {
520+
self.to_ascii_string().into()
521+
}
522+
}
523+
517524
impl<'a> From<&'a AsciiStr> for &'a [AsciiChar] {
518525
#[inline]
519526
fn from(astr: &AsciiStr) -> &[AsciiChar] {
@@ -1493,10 +1500,9 @@ mod tests {
14931500
#[test]
14941501
#[cfg(feature = "alloc")]
14951502
fn to_and_from_byte_box() {
1496-
let s = "abc".as_ascii_str().unwrap().to_ascii_string();
1497-
let boxed = s.clone().into_boxed_ascii_str();
1503+
let s = "abc".as_ascii_str().unwrap().to_ascii_string().into_boxed_ascii_str();
14981504
unsafe {
1499-
let converted = boxed.into_boxed_bytes();
1505+
let converted = s.clone().into_boxed_bytes();
15001506
assert_eq!(&converted[..], &b"abc"[..]);
15011507
let converted_back = AsciiStr::from_boxed_ascii_bytes_unchecked(converted);
15021508
assert_eq!(&converted_back[..], &s[..]);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy