about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorJake Goulding <jake.goulding@gmail.com>2015-06-03 17:35:50 -0400
committerJake Goulding <jake.goulding@gmail.com>2015-06-05 22:27:09 -0400
commit97294be30c8712a91060d0ce043adefb4f867db8 (patch)
tree81adae15965d22d0ea5328e56715cd5b90faa56d /src/libstd
parentc78c0994b1df5e365058f301330d06fa035c3734 (diff)
downloadrust-97294be30c8712a91060d0ce043adefb4f867db8.tar.gz
rust-97294be30c8712a91060d0ce043adefb4f867db8.zip
Convert CString to a Box<[u8]>
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/ffi/c_str.rs17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/libstd/ffi/c_str.rs b/src/libstd/ffi/c_str.rs
index 8c066b3dc2e..9bc9e7530dd 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<u8>,
+    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<u8>) -> CString {
         v.push(0);
-        CString { inner: v }
+        CString { inner: v.into_boxed_slice() }
     }
 
     /// Returns the contents of this `CString` as a slice of bytes.
@@ -218,6 +220,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;