1010
1111#![ unstable( feature = "std_misc" ) ]
1212
13- use borrow:: Cow ;
13+ use borrow:: { Cow , ToOwned } ;
14+ use boxed:: Box ;
15+ use clone:: Clone ;
1416use convert:: { Into , From } ;
1517use cmp:: { PartialEq , Eq , PartialOrd , Ord , Ordering } ;
1618use 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" ) ]
6668pub 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" ) ]
221230impl Deref for CString {
222231 type Target = CStr ;
0 commit comments