Skip to content

Commit 63ca95a

Browse files
fix MSRV
1 parent 60a8e04 commit 63ca95a

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

src/conversions/std/cstring.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use std::str::Utf8Error;
66
#[cfg(any(Py_3_10, not(Py_LIMITED_API)))]
77
use {
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
}

0 commit comments

Comments
 (0)