10
10
11
11
#![ unstable( feature = "std_misc" ) ]
12
12
13
- use borrow:: Cow ;
13
+ use borrow:: { Cow , ToOwned } ;
14
+ use boxed:: Box ;
15
+ use clone:: Clone ;
14
16
use convert:: { Into , From } ;
15
17
use cmp:: { PartialEq , Eq , PartialOrd , Ord , Ordering } ;
16
18
use error:: Error ;
@@ -61,10 +63,10 @@ use vec::Vec;
61
63
/// }
62
64
/// # }
63
65
/// ```
64
- #[ derive( Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
66
+ #[ derive( PartialEq , PartialOrd , Eq , Ord , Hash ) ]
65
67
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
66
68
pub struct CString {
67
- inner : Vec < u8 > ,
69
+ inner : Box < [ u8 ] > ,
68
70
}
69
71
70
72
/// Representation of a borrowed C string.
@@ -197,7 +199,7 @@ impl CString {
197
199
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
198
200
pub unsafe fn from_vec_unchecked ( mut v : Vec < u8 > ) -> CString {
199
201
v. push ( 0 ) ;
200
- CString { inner : v }
202
+ CString { inner : v. into_boxed_slice ( ) }
201
203
}
202
204
203
205
/// Returns the contents of this `CString` as a slice of bytes.
@@ -217,6 +219,13 @@ impl CString {
217
219
}
218
220
}
219
221
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
+
220
229
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
221
230
impl Deref for CString {
222
231
type Target = CStr ;
0 commit comments