I’ve always wanted one in a language I’d have some reason to use, ever since learning Pascal as a kid. I think they’re less ambiguous, and thus easier to work with. With C you can use [0], which is kind of a poor-man’s postfix dereferencing operator… But in Rust, it seems you have to resort to parentheses to deal with the ambiguity? Consider this program, demonstrating the ambiguity:
use std::ops::Deref;
struct Foo(Bar);
struct Bar(Baz);
struct Baz;
impl Deref for Foo {
type Target = Bar;
fn deref<'a>(&'a self) -> &'a Bar {
println!("Deref Foo");
&self.0
}
}
impl Deref for Bar {
type Target = Baz;
fn deref<'a>(&'a self) -> &'a Baz {
println!("deref Bar");
&self.0
}
}
fn main() {
let x = Foo(Bar(Baz));
let _ = *x;
let _ = *x.0;
let _ = (*x).0;
}
(playground)
On the other hand, the ambiguity would be removed with a postfix dereferencing operator:
fn main() {
let x = Foo(Bar(Baz));
let _ = x*;
let _ = x.0*;
let _ = x*.0;
}
(aside: I know this would allow a syntactic ambiguity on something like x.0 * 3… it’s the same ambiguity that currently exists on 3 * x.0, just with the terms reversed.)
I know this won’t happen at this point, but it would have been nice…