Single element tuple structs fit many uses, such as the NewType pattern explained in the Rust Book where a type defined elsewhere is extended with custom traits or methods. (can they be used to restrict against usage of methods as well?)
When indexing into a single element tuple struct, you must use syntax to indicate which element is being indexed, e.g. my_var.0
. This seems redundant, and this also implies that there are other elements present.
How possible would it be to remove the redundant indexing? A potential problem I could think of is assignment: let my_var2 = my_var
which would have unclear semantics of whether the tuple struct is being assigned or the variable within the tuple struct was being assigned. However, assignment of the variable within the tuple struct seems like an unusual use case, which would be a case where an explicit indexing my_var.0
would be required.
I would like it if I could define a single element tuple struct to not require extra indexing.