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::Iter)
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.

You’ve already gotten a reply to : vs = in struct constructors over at internals.

The use of :: is actually pretty consistent: in every case, it indicates namespace (module or type) traversal: from is an item in String. Iter is an item in env. env is an item in std.

And as for . I’m wondering about your background; in just about any popular language (that has methods) field access and method calls share a common syntax.

3 Likes

Let’s keep this discussion in one place. Closing this in favor of the thread on Internals.

2 Likes