File tree Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -781,8 +781,15 @@ const unsafe fn strlen(ptr: *const c_char) -> usize {
781781pub struct Bytes < ' a > {
782782 // since we know the string is nul-terminated, we only need one pointer
783783 ptr : NonNull < u8 > ,
784- phantom : PhantomData < & ' a u8 > ,
784+ phantom : PhantomData < & ' a [ c_char ] > ,
785785}
786+
787+ #[ unstable( feature = "cstr_bytes" , issue = "112115" ) ]
788+ unsafe impl Send for Bytes < ' _ > { }
789+
790+ #[ unstable( feature = "cstr_bytes" , issue = "112115" ) ]
791+ unsafe impl Sync for Bytes < ' _ > { }
792+
786793impl < ' a > Bytes < ' a > {
787794 #[ inline]
788795 fn new ( s : & ' a CStr ) -> Self {
@@ -815,7 +822,7 @@ impl Iterator for Bytes<'_> {
815822 if ret == 0 {
816823 None
817824 } else {
818- self . ptr = self . ptr . offset ( 1 ) ;
825+ self . ptr = self . ptr . add ( 1 ) ;
819826 Some ( ret)
820827 }
821828 }
@@ -825,6 +832,12 @@ impl Iterator for Bytes<'_> {
825832 fn size_hint ( & self ) -> ( usize , Option < usize > ) {
826833 if self . is_empty ( ) { ( 0 , Some ( 0 ) ) } else { ( 1 , None ) }
827834 }
835+
836+ #[ inline]
837+ fn count ( self ) -> usize {
838+ // SAFETY: We always hold a valid pointer to a C string
839+ unsafe { strlen ( self . ptr . as_ptr ( ) . cast ( ) ) }
840+ }
828841}
829842
830843#[ unstable( feature = "cstr_bytes" , issue = "112115" ) ]
You can’t perform that action at this time.
0 commit comments