File tree Expand file tree Collapse file tree 1 file changed +2
-8
lines changed Expand file tree Collapse file tree 1 file changed +2
-8
lines changed Original file line number Diff line number Diff line change @@ -6,7 +6,6 @@ use std::str::Utf8Error;
66#[ cfg( any( Py_3_10 , not( Py_LIMITED_API ) ) ) ]
77use {
88 crate :: { exceptions:: PyValueError , ffi} ,
9- std:: ffi:: FromBytesWithNulError ,
109 std:: slice,
1110} ;
1211
@@ -79,12 +78,7 @@ impl<'a> FromPyObject<'a, '_> for &'a CStr {
7978 // SAFETY: PyUnicode_AsUTF8AndSize always returns a NUL-terminated string
8079 let slice = unsafe { slice:: from_raw_parts ( ptr. cast ( ) , size as usize + 1 ) } ;
8180
82- CStr :: from_bytes_with_nul ( slice) . map_err ( |err| match err {
83- FromBytesWithNulError :: InteriorNul { .. } => PyValueError :: new_err ( err. to_string ( ) ) ,
84- FromBytesWithNulError :: NotNulTerminated => {
85- unreachable ! ( "PyUnicode_AsUTF8AndSize always returns a NUL-terminated string" )
86- }
87- } )
81+ CStr :: from_bytes_with_nul ( slice) . map_err ( |err| PyValueError :: new_err ( err. to_string ( ) ) )
8882 }
8983}
9084
@@ -186,7 +180,7 @@ mod tests {
186180 assert_eq ! ( py_string. to_cow( ) . unwrap( ) , s) ;
187181
188182 let roundtripped: Cow < ' _ , CStr > = py_string. extract ( ) . unwrap ( ) ;
189- assert_eq ! ( roundtripped, cstr) ;
183+ assert_eq ! ( roundtripped. as_ref ( ) , cstr. as_c_str ( ) ) ;
190184 } )
191185 }
192186}
You can’t perform that action at this time.
0 commit comments