Simplify to_c_error by using NonNull inline

This commit is contained in:
David Tolnay 2021-01-02 16:23:00 -08:00
parent 6c12520836
commit 837eefee5e
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82

View File

@ -41,14 +41,11 @@ unsafe fn to_c_error(msg: String) -> Result {
extern "C" {
#[link_name = "cxxbridge1$error"]
fn error(ptr: *const u8, len: usize) -> *const u8;
fn error(ptr: *const u8, len: usize) -> NonNull<u8>;
}
let copy = error(ptr, len);
let err = PtrLen {
ptr: NonNull::new_unchecked(copy as *mut u8),
len,
};
let err = PtrLen { ptr: copy, len };
Result { err }
}