Hands-on Rust: "Structs can also be tuples" (page 150, B2.0)

Notice that the syntax is different here. Structs can also be tuples. If you only have one piece of information to store inside a struct, you can replace the named fields with (pub type)—in this case, String. You can then access the contents of the structure just like a tuple - mystruct.0 contains the string.

Aside from less typing, what is the benefit of using this syntax? I’m guessing that it’s supported by Rust, so you’re introducing it here so that the reader is familiar with the approach?

1 Like