Recently, I made a pre-rfc about potential optional fields in methods. The general feedback was that the syntax should be more generic, and be applicable to more places.
This is one idea that stemmed from it, which I think would be quite useful in a variety of cases. There's another one that I'm still debating whether to do, as it was suggested lots to split it into two parts (it's
Into syntactic sugar
You can use the postfix
! operator to automatically
.into() an expression.
- (Directly from the original pre-RFC) Configuration structs, or structs with many
Options. When using these with struct literals, doing
foo: 3!is a lot more readable imo and less verbose than
- Functions that take in
Intoas an argument, to accept more types. This means, in the function, you can use the input parameter with
!. I'm also considering whether we should have this operator in patterns, so a function could take
foo!: Into<Bar>, say, and
foowould be of type
- Functions that don't take
Intoas an argument, to convert your types without specifying
- Signifies intent clearly
- Does not reduce readability
Won't this get confused with macros?
This was one of my concerns when I thought of this idea; however, macros can only be called with brackets afterwards. In most cases where you'd use this, you wouldn't be specifying brackets afterwards, and as such, that will attempt to invoke a macro instead.
Of course, if there's a more suitable operator to use, please say.