Re:Rust's unsafe pointer types need an overhaul
by nickitolas on Sunday March 20, 2022 @04:56AM
(#30741179)
I think the familiarity might be a double edged sword, since AIUI the proposed operator has different semantics. "ptr~field~field2" is not "ptr->field->field2", it's more like "&(&ptr->field)->field2". Therefore I feel like the familiarity might just confuse people or give them a false sense of security.
[ Parent
| on HN ]
Re:Rust's unsafe pointer types need an overhaul
by xorvoid on Sunday March 20, 2022 @07:09AM
(#30741684)
Meh. It’s harmless. You get a helpful compiler error the first time and you very quickly learn. I’ve been a C programmer for >20 years and this slight difference wouldn’t bother me.
Explaining it is simple:
‘.’ uses a reference and produces a reference
‘->’ uses a pointer and produces a pointer
Re:Rust's unsafe pointer types need an overhaul
by heinrich5991 on Sunday March 20, 2022 @09:50AM
(#30742572)
`.` only produces a reference if you explicitly reference the result.
`a.b` is of type `B`, only `&a.b` is `&B` and `&mut a.b` is `&mut B`. This is unlike your proposal of `->` where `a->b` would be `*const B`.