mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-21 22:34:05 +00: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:
commit
b9075d6f53
@ -20,7 +20,7 @@ use iter::Iterator;
|
||||
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 @@ impl CString {
|
||||
}
|
||||
|
||||
#[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 @@ impl ToOwned for CStr {
|
||||
}
|
||||
}
|
||||
|
||||
#[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::*;
|
||||
|
Loading…
Reference in New Issue
Block a user