File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed
Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -731,6 +731,23 @@ impl<'a> CStrBytes<'a> {
731731 // the nul terminator.
732732 unsafe { * self . ptr . as_ref ( ) == 0 }
733733 }
734+
735+ /// Returns the remainder of the string as a slice.
736+ #[ unstable( feature = "cstr_bytes" , issue = "none" ) ]
737+ #[ inline]
738+ pub fn as_c_str ( & self ) -> & ' a CStr {
739+ // SAFETY: We start with a valid C string and never increment beyond the
740+ // nul terminator, retaining a valid C string, even if it's empty.
741+ unsafe { CStr :: from_ptr ( self . ptr . as_ptr ( ) as * mut u8 as * const c_char ) }
742+ }
743+ }
744+
745+ #[ unstable( feature = "cstr_bytes" , issue = "none" ) ]
746+ impl AsRef < CStr > for CStrBytes < ' _ > {
747+ #[ inline]
748+ fn as_ref ( & self ) -> & CStr {
749+ self . as_c_str ( )
750+ }
734751}
735752
736753#[ unstable( feature = "cstr_bytes" , issue = "none" ) ]
You can’t perform that action at this time.
0 commit comments