Is there a standard library function/methods for getting a *mut T
out of an Option<&mut T>
? I.e. None
turns into a null pointer. That is, the inverse of as_ref
on primitive pointer types?
Would Option::map_or
work for this?
use std::ptr;
fn main() {
let mut x = 7i32;
let xr = Some(&mut x);
let xp = xr.map_or(ptr::null(), |r| r as *mut i32);
println!("{:?}", xp);
}
Yes, but I'm trying to find out if there's a standard library method that does that and hides the boilerplate.
map_or
and other Option
method that take Fn*
is standard library method
to convert Option
to something else.