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.
Loading
Please register or sign in to comment