Skip to content
Commit b2caf477 authored by Stefan Bühler's avatar Stefan Bühler
Browse files

Add and use ForeignTypeRefExt::from_const_ptr

1. `X::from_ptr(p as *mut _)` is dangerous, as it not only casts
   `*const X::CType` to `*mut X::CType`, but any `*const U` to
   `*mut X::CType`.
   Add and use a extension trait to provide `from_const_ptr`.
2. Often null pointers are returned as `Option<...>`; refactor the checks
   into `from_const_ptr_opt` for refs and `from_ptr_opt` for owned data.
3. `assert!(!p.is_null())` is easy to mistype as `assert!(p.is_null());`.
   Use `X::from(_const)?ptr_opt(...).expect("...")` instead.
parent 32b17363
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment