I have some questions on zero sized types, primarily about syntaxes. Let me show some code below:
struct SNah;
struct SEmpty {}
struct SEmptyTuple();
struct STuple(i32);
fn main() {
// ok
let s_nah = SNah;
// ok
let s_nah = SNah {};
// not ok, must include `{}` to compile
let s_empty = SEmpty;
// ok
let s_empty = SEmpty {};
// ok... but is actually a fn() -> SEmptyTuple
let s_empty_tuple = SEmptyTuple;
// call the function to get a concrete variable with type SEmptyTuple
let s_empty_tuple_real = s_empty_tuple();
// another try for a normal tuple struct
// s_tuple is a fn(i32) -> STuple, i.e. the plain c`tor in a function type
let s_tuple = STuple;
// call the function to get a concrete variable
let s_tuple_real = s_tuple(42);
// typical way to construct the tuple
let s_tuple_real = STuple(1024);
}
My questions:
-
SNahandSEemptyseem to have identical functionalities. If so, why allowing two declaring syntaxes on empty structs? - Continuing 1., why the nuances on declaring variables (the optional
{}v.s. required{})? - Why allowing function type aliasing on tuple structs (e.g. the
s_tuple(42)stuff)? That doesn't seem helping in any situations, and it creates confusions especially when your tuple struct is empty (theSEmptyTuplev.s.SEmptyTuple()declaration, two totally distinct types).