One situation I had quite recently where a postfix borrow would have been nice, is when you want to call a trait method on a field of &self with type T that is implemented both for T and &T and you need to specify that you want to use the latter implementation, because you can't move out of self. The only way to do this right now is with quite a lot of parentheses.
struct Foo(Bar);
struct Bar(i32);
impl From<Bar> for i32 {
fn from(val: Bar) -> Self {
val.0
}
}
impl From<&Bar> for i32 {
fn from(val: &Bar) -> Self {
val.0
}
}
impl Foo {
fn plus_one(&self) -> i32 {
// I think this could be: self.0&.into();
let val: i32 = (&(self.0)).into();
val + 1
}
}
This came up with strum_macros::IntoStaticStr where I wanted a method that uses the generated string and returns it in a different casing.
I remember a case where I had a trait implemented for both a type and its reference. In this case both owned.borrow().foo() (after importing Borrow) and (&owned).foo() work to call the trait on the reference, and it was rare enough that it did not really need to be more concise.
Really want postfix dereferences due to 2 use cases:
unsafe code
yew used antipattern with implementing Deref and something else on a type (Clone for example) so I am constantly writing stuff like (*var).clone() (in yew you need to clone very often, as stuff is reference counted and rust does not have something like Capture or Claim trait that will clone automatically when captured to some closure)
Something like .& would've removed the need for convenience methods like Vec::iter and Iterator::by_ref, you could just use IntoIterator for &T ergonomically. Those are idiomatic at this point (and arguably more explicit) but others have pointed out similar cases. And it's symmetric with deref so wouldn't be much more to implement or learn.
Only if you use std::ops::Not, as previously discussed. I think it should become an intrinsic method just to make that unnecessary, and so that it shows up under "Methods", next to then and then_some, in the sidebar at https://doc.rust-lang.org/std/primitive.bool.html.
Once we have inherent traits, I'd love to make Not inherent to bool. But I have the impression that multiple people on libs do not support .not(), whatever the implementation. (I may be mistaken, or those opinions may have shifted.)