You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the "Data Types" section, a way of accessing the elements of a tuple discussed in this tutorial is through destructuring. Under "Tuple structs", it is suggested that this is the only way of accessing tuple elements:
Their fields must be accessed by destructuring (like a tuple), rather than by name.
However, there is another way of accessing tuple elements: through "dot notation". Tuple elements can be accessed directly by using a period (.) followed by the index of the value. For example:
fnbar(x:(i32,i32)){println!("x was ({}, {})", x.0, x.1);// Note the `x.0` and `x.1`.}
This can also be applied to tuple structs:
structIntPoint(i32,i32);fnfoo(x:IntPoint){println!("x was ({}, {})", x.0, x.1);// Note the `x.0` and `x.1`.}
It is quite intriguing to me as to why this is left out, because this syntax is encountered early on in the Rust Programming Language book.
The text was updated successfully, but these errors were encountered:
In the "Data Types" section, a way of accessing the elements of a tuple discussed in this tutorial is through destructuring. Under "Tuple structs", it is suggested that this is the only way of accessing tuple elements:
However, there is another way of accessing tuple elements: through "dot notation". Tuple elements can be accessed directly by using a period (
.
) followed by the index of the value. For example:This can also be applied to tuple structs:
It is quite intriguing to me as to why this is left out, because this syntax is encountered early on in the Rust Programming Language book.
The text was updated successfully, but these errors were encountered: