Rust allows you to initialize an object with a literal form. This form is composed by the name of the type, of keys that will indicate the beginning and end of this literal, as if it were the quotation marks of a string, and then you put the members who want to initialize the object data.
Rust has no constructor like other languages, it may have simple functions that serve as constructors, but the most commonly used form is the pure and simple initialization of this form of literal.
So it looks like a function call with named arguments, only what you’re doing is using the names of the members of the struct
and its values. So what is before the :
is the name of the member and what is after the :
is the value to be attributed to that member.
In this example you’re a guy Complex
, re
is the real part of the number and im
is the imaginary part. It has nothing to do with what you speculated in the question, it is much simpler than this. This information has to do with the type of data there, the Complex
and not with language rules. The language only determines the syntax of this object initializer.
Another hypothetical example:
let joao = Funcionario { nome : "João", salario : 1000 };
I put in the Github for future reference.
Get it? They’re just members of the struct
, And by the way, by the way, by the way, by the way, you look like a C, not a Rust.
Have you studied complex numbers before? It consists of a real part (Re) and an imaginary part (Im).
– Woss