unless you are dealing with unitialized memory (e.g. the dereferenced value has not been fully initialized or has been partially moved), it's mostly the same whether using the * operator or using as_ref()/as_mut()[1]. if you want to move the dereferenced value, neither * nor a reference allows you do it anyway.
often times, using the * operator would result implicitly reborrows of the value ↩︎
Unfortunately I'm iteratively refactoring a c codebase, so sometimes I am dealing with unintialized memory. Once I've refactored enough of it to be sure all uses are initialized and there are never multiple instances of exclusive references I will try to switch things over to rust references.
well, that's a bummer. in such situation, I would probably only use NonNull at API bounaries, and get a raw pointer from it as soon as possible:
fn foo(p: NonNull<Bar>) {
let p = p.as_ptr();
//...
}
for struct fields, if they are private fields, I would just use raw pointers (while the constructor probably takes a NonNull), but for public fields, I would stick to NonNull (or Option<NonNull>, depending on the sementics).
if theres too much of it to really bother me, the best I can do is to use a short name macro. but I think it probably won't help much in terms of ergonomics, it may even be worse in terms of readability (unless postfix marco syntax became reality, which should solve both the ergonomics and readablity issue), but other than that, I don't know how else can I reduce the typing.