@@ -20,7 +20,7 @@ use iter::Iterator;
2020use libc;
2121use mem;
2222use memchr;
23- use ops:: Deref ;
23+ use ops;
2424use option:: Option :: { self , Some , None } ;
2525use os:: raw:: c_char;
2626use result:: Result :: { self , Ok , Err } ;
@@ -282,7 +282,7 @@ impl CString {
282282}
283283
284284#[ stable( feature = "rust1" , since = "1.0.0" ) ]
285- impl Deref for CString {
285+ impl ops :: Deref for CString {
286286 type Target = CStr ;
287287
288288 fn deref ( & self ) -> & CStr {
@@ -522,6 +522,37 @@ impl ToOwned for CStr {
522522 }
523523}
524524
525+ #[ unstable( feature = "cstring_asref" , reason = "recently added" , issue = "0" ) ]
526+ impl ops:: Index < ops:: RangeFull > for CString {
527+ type Output = CStr ;
528+
529+ #[ inline]
530+ fn index ( & self , _index : ops:: RangeFull ) -> & CStr {
531+ self
532+ }
533+ }
534+
535+ #[ unstable( feature = "cstring_asref" , reason = "recently added" , issue = "0" ) ]
536+ impl < ' a , T : ?Sized + AsRef < CStr > > From < & ' a T > for CString {
537+ fn from ( s : & ' a T ) -> CString {
538+ s. as_ref ( ) . to_owned ( )
539+ }
540+ }
541+
542+ #[ unstable( feature = "cstring_asref" , reason = "recently added" , issue = "0" ) ]
543+ impl AsRef < CStr > for CStr {
544+ fn as_ref ( & self ) -> & CStr {
545+ self
546+ }
547+ }
548+
549+ #[ unstable( feature = "cstring_asref" , reason = "recently added" , issue = "0" ) ]
550+ impl AsRef < CStr > for CString {
551+ fn as_ref ( & self ) -> & CStr {
552+ self
553+ }
554+ }
555+
525556#[ cfg( test) ]
526557mod tests {
527558 use prelude:: v1:: * ;
0 commit comments