Convert CString to a Box<[u8]>
This commit is contained in:
parent
c78c0994b1
commit
97294be30c
1 changed files with 13 additions and 4 deletions
|
|
@ -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.
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue