Skip to content

Commit 2ebc3e3

Browse files
committed
Convert CString to a Box<[u8]>
1 parent baf508b commit 2ebc3e3

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/libstd/ffi/c_str.rs

+13-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010

1111
#![unstable(feature = "std_misc")]
1212

13-
use borrow::Cow;
13+
use borrow::{Cow, ToOwned};
14+
use boxed::Box;
15+
use clone::Clone;
1416
use convert::{Into, From};
1517
use cmp::{PartialEq, Eq, PartialOrd, Ord, Ordering};
1618
use error::Error;
@@ -61,10 +63,10 @@ use vec::Vec;
6163
/// }
6264
/// # }
6365
/// ```
64-
#[derive(Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
66+
#[derive(PartialEq, PartialOrd, Eq, Ord, Hash)]
6567
#[stable(feature = "rust1", since = "1.0.0")]
6668
pub struct CString {
67-
inner: Vec<u8>,
69+
inner: Box<[u8]>,
6870
}
6971

7072
/// Representation of a borrowed C string.
@@ -197,7 +199,7 @@ impl CString {
197199
#[stable(feature = "rust1", since = "1.0.0")]
198200
pub unsafe fn from_vec_unchecked(mut v: Vec<u8>) -> CString {
199201
v.push(0);
200-
CString { inner: v }
202+
CString { inner: v.into_boxed_slice() }
201203
}
202204

203205
/// Returns the contents of this `CString` as a slice of bytes.
@@ -217,6 +219,13 @@ impl CString {
217219
}
218220
}
219221

222+
#[stable(feature = "rust1", since = "1.0.0")]
223+
impl Clone for CString {
224+
fn clone(&self) -> Self {
225+
CString { inner: self.inner.to_owned().into_boxed_slice() }
226+
}
227+
}
228+
220229
#[stable(feature = "rust1", since = "1.0.0")]
221230
impl Deref for CString {
222231
type Target = CStr;

0 commit comments

Comments
 (0)