mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
Auto merge of #30616 - arcnmx:cstr-asref, r=aturon
Are trait impls still insta-stable? Considering that this design has been around for a long time on `String` and `OsString` it probably doesn't matter much... The `From` impl is a bit strange to me. It's stolen from `OsString` but I'm not really sure about it... `String` just impls `From<&str>` instead, would that make more sense?
This commit is contained in:
+33
-2
@@ -20,7 +20,7 @@
|
||||
use libc;
|
||||
use mem;
|
||||
use memchr;
|
||||
use ops::Deref;
|
||||
use ops;
|
||||
use option::Option::{self, Some, None};
|
||||
use os::raw::c_char;
|
||||
use result::Result::{self, Ok, Err};
|
||||
@@ -282,7 +282,7 @@ pub fn as_bytes_with_nul(&self) -> &[u8] {
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl Deref for CString {
|
||||
impl ops::Deref for CString {
|
||||
type Target = CStr;
|
||||
|
||||
fn deref(&self) -> &CStr {
|
||||
@@ -522,6 +522,37 @@ fn to_owned(&self) -> CString {
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "cstring_asref", since = "1.7.0")]
|
||||
impl<'a> From<&'a CStr> for CString {
|
||||
fn from(s: &'a CStr) -> CString {
|
||||
s.to_owned()
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "cstring_asref", since = "1.7.0")]
|
||||
impl ops::Index<ops::RangeFull> for CString {
|
||||
type Output = CStr;
|
||||
|
||||
#[inline]
|
||||
fn index(&self, _index: ops::RangeFull) -> &CStr {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "cstring_asref", since = "1.7.0")]
|
||||
impl AsRef<CStr> for CStr {
|
||||
fn as_ref(&self) -> &CStr {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "cstring_asref", since = "1.7.0")]
|
||||
impl AsRef<CStr> for CString {
|
||||
fn as_ref(&self) -> &CStr {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use prelude::v1::*;
|
||||
|
||||
Reference in New Issue
Block a user