The grammar of rustlang feels a bit confusing and has no rules to follow

The ‘.’ symbol may be followed by a function or structure field, such as “a.b()” or “a.b”; The ‘:’ symbol may be followed by the data type or the data itself within the structure, such as “struct A{a:u32}” or “let a=A{a:0}”; The ‘::’ symbol may be followed by a function or data type, such as “String::from(“aa”)” or “fn new(mut args: std::env::Args)”; If you assign a value to a field within a structure, it would be better to replace ‘:’ with ‘=’; The type name can only be used after the ‘:’ symbol, and the function name can only be used after the ‘::’ symbol.

It’s hard to tell what you’re actually trying to get across here, but here’s some random thoughts that might help:

For the odd claim that the grammar “has no rules”, you might be interested in https://doc.rust-lang.org/reference/expressions.html and https://github.com/rust-lang-nursery/wg-grammar

If the claim is just that these syntax decisions are somewhat arbitrary, then yes, that’s true of pretty much every language. If the claim is that some tokens have multiple meanings, that’s also extremely common and as far as I know no one’s made a convincing argument that any of them are particularly harmful; in cases like the . it’s probably beneficial to use a single sigil for multiple intuitively similar operations (in fact, fields vs methods is only scratching the surface of the many things . can do).

Specifically on the use of : in struct initialization syntax, there’s actually a lot of people who agree that = would’ve been a better choice (I personally don’t care either way). But more importantly, everyone seems to agree that it’s not a big deal either way and nowhere near worth the churn of introducing a second syntax now.

7 Likes

Lol, now there is also .await :wink:

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.