5 ms·
> Its very easy to build a mental model of the period operator as simply the introduction of all of these various postfix syntaxes: field accesses, methods, and
by nixpulvis 8y ago
> Its very easy to build a mental model of the period operator as simply the introduction of all of these various postfix syntaxes: field accesses, methods, and certain keyword operators like the await operation. (In this model, even the ? operator can be thought of as a modification on the period construct.)
I like this explanation.
But this whole post could really use some more concrete examples of the at the very least the final style being used in various situations. Not just mainly `expression.await`.
Keep up the work on this, I'm excited to use this in my projects.
- Sharlin 8y agoMy dislike for the ”dot keyword” syntax has been strong, but if it is selected, hopefully it’s at least generalized to other keywords in the future, so that `.await` doesn’t stay a lone awkward exception to what dot notation means. In particular, I wouldn’t mind if in the future `expr?` could be spelled `expr.try` for consistency (even at the expense of introducing redundancy).
- saghm 8y agoI like that idea for try! Near the bottom of the blog post, they mention that `match` could become a "dot keyword" expression, giving the following example: foo.bar(..).baz(..).match { Variant1 => { ... } Variant2(quux) => { ... } }
- faitswulff 8y agoThe post says as much: > In particular, some members of the language team are excited about a potential future extensions in which some “expression-oriented” keywords (that is, those that evaluate to something other than ! or ()) can all be called in a “method-like” fashion. In this world, the dot await operation would be generalized so that await were a “normal” prefix keyword, but the dot combination applied to several such keywords, most importantly match:
- Sharlin 8y agoYeah, that’s what I referred to, just wasn’t very clear.
- gamegoblin 8y agoI wonder if I would ever find something like my_iter .foo() .bar() .return more appealing than return my_iter .foo() .bar(); I could see it happening, but I'll definitely need some time to get used to it.
- nixpulvis 8y agoSee, now this is exactly my issue with this syntax, I generally expect to be able to "chain" things with the "." notation.
- mintplant 8y agoYou can chain .await, though. let n = future_of_future_of_int .await .await;
- asdkhadsj 8y agoCuriously, will there be limitations to where it can be used? Eg, imagine a `foos.iter().map(|f| f.await).collect::<Vec<_>>()`? That seems crazy, think it'll be possible?
- comex 8y agoNot as things are currently designed. This is similar to how you can’t use things like the `?` operator, break, return, etc. inside a lambda and expect it to affect the outer function: it doesn’t work because lambdas are treated as their own functions. Personally I think it would be cool to pursue an extension to lambdas that would allow some of those things to work, but I’m not a Rust team member or anything, just an interested observer.
- swsieber 8y agoTechnically, `?` can work in lambda's if the return value is a `Result` - though it won't work like it's being called as part of a normal loop or whatever. That's largely mitigated by the combinators available on an interator of `Result`s. So I think we'll just need similar tooling for lambdas - perhaps an `async` modifier for them? That (I think) would lift await stuff up to `?` in terms of lambda support.
- deleted 8y ago[deleted]