diff --git a/src/libstd/ffi/c_str.rs b/src/libstd/ffi/c_str.rs index 8c066b3dc2e8..9bc9e7530dd2 100644 --- a/src/libstd/ffi/c_str.rs +++ b/src/libstd/ffi/c_str.rs @@ -10,7 +10,9 @@ #![unstable(feature = "std_misc")] -use borrow::Cow; +use borrow::{Cow, ToOwned}; +use boxed::Box; +use clone::Clone; use convert::{Into, From}; use cmp::{PartialEq, Eq, PartialOrd, Ord, Ordering}; use error::Error; @@ -61,10 +63,10 @@ use vec::Vec; /// } /// # } /// ``` -#[derive(Clone, PartialEq, PartialOrd, Eq, Ord, Hash)] +#[derive(PartialEq, PartialOrd, Eq, Ord, Hash)] #[stable(feature = "rust1", since = "1.0.0")] pub struct CString { - inner: Vec, + inner: Box<[u8]>, } /// Representation of a borrowed C string. @@ -197,7 +199,7 @@ impl CString { #[stable(feature = "rust1", since = "1.0.0")] pub unsafe fn from_vec_unchecked(mut v: Vec) -> CString { v.push(0); - CString { inner: v } + CString { inner: v.into_boxed_slice() } } /// Returns the contents of this `CString` as a slice of bytes. @@ -217,6 +219,13 @@ impl CString { } } +#[stable(feature = "rust1", since = "1.0.0")] +impl Clone for CString { + fn clone(&self) -> Self { + CString { inner: self.inner.to_owned().into_boxed_slice() } + } +} + #[stable(feature = "rust1", since = "1.0.0")] impl Deref for CString { type Target = CStr;