diff options
| author | bors <bors@rust-lang.org> | 2015-12-31 20:52:17 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2015-12-31 20:52:17 +0000 |
| commit | b9075d6f533b2fceec125fa5afcedbb8e846ba72 (patch) | |
| tree | d454480f17bc5670c57d8a027d67415e03ee30ff /src/libstd | |
| parent | 7d9543345c785ea777671baab306d95fed8ee94b (diff) | |
| parent | 53878e7546e3e6f3665dea572fbfa48f005ecad2 (diff) | |
| download | rust-b9075d6f533b2fceec125fa5afcedbb8e846ba72.tar.gz rust-b9075d6f533b2fceec125fa5afcedbb8e846ba72.zip | |
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?
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/ffi/c_str.rs | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/src/libstd/ffi/c_str.rs b/src/libstd/ffi/c_str.rs index 3f3913471b8..9a41272299e 100644 --- a/src/libstd/ffi/c_str.rs +++ b/src/libstd/ffi/c_str.rs @@ -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::*; |
