@@ -20,7 +20,7 @@ use iter::Iterator;
20
20
use libc;
21
21
use mem;
22
22
use memchr;
23
- use ops:: Deref ;
23
+ use ops;
24
24
use option:: Option :: { self , Some , None } ;
25
25
use os:: raw:: c_char;
26
26
use result:: Result :: { self , Ok , Err } ;
@@ -282,7 +282,7 @@ impl CString {
282
282
}
283
283
284
284
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
285
- impl Deref for CString {
285
+ impl ops :: Deref for CString {
286
286
type Target = CStr ;
287
287
288
288
fn deref ( & self ) -> & CStr {
@@ -522,6 +522,37 @@ impl ToOwned for CStr {
522
522
}
523
523
}
524
524
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
+
525
556
#[ cfg( test) ]
526
557
mod tests {
527
558
use prelude:: v1:: * ;
0 commit comments