@@ -1085,6 +1085,15 @@ let p = Point(10, 11);
10851085let px: int = match p { Point(x, _) => x };
10861086~~~~
10871087
1088+ A _ unit-like struct_ is a structure without any fields, defined by leaving off the fields list entirely.
1089+ Such types will have a single value, just like the [ unit value ` () ` ] ( #unit-and-boolean-literals ) of the unit type.
1090+ For example:
1091+
1092+ ~~~~
1093+ struct Cookie;
1094+ let c = [Cookie, Cookie, Cookie, Cookie];
1095+ ~~~~
1096+
10881097### Enumerations
10891098
10901099An _ enumeration_ is a simultaneous definition of a nominal [ enumerated type] ( #enumerated-types ) as well as a set of * constructors* ,
@@ -1590,7 +1599,8 @@ struct_expr : expr_path '{' ident ':' expr
15901599 [ ',' ident ':' expr ] *
15911600 [ ".." expr ] '}' |
15921601 expr_path '(' expr
1593- [ ',' expr ] * ')'
1602+ [ ',' expr ] * ')' |
1603+ expr_path
15941604~~~~~~~~
15951605
15961606There are several forms of structure expressions.
@@ -1600,23 +1610,28 @@ providing the field values of a new instance of the structure.
16001610A field name can be any identifier, and is separated from its value expression by a colon.
16011611To indicate that a field is mutable, the ` mut ` keyword is written before its name.
16021612
1603- A _ tuple structure expression_ constists of the [ path] ( #paths ) of a [ structure item] ( #structures ) ,
1613+ A _ tuple structure expression_ consists of the [ path] ( #paths ) of a [ structure item] ( #structures ) ,
16041614followed by a parenthesized list of one or more comma-separated expressions
16051615(in other words, the path of a structured item followed by a tuple expression).
16061616The structure item must be a tuple structure item.
16071617
1618+ A _ unit-like structure expression_ consists only of the [ path] ( #paths ) of a [ structure item] ( #structures ) .
1619+
16081620The following are examples of structure expressions:
16091621
16101622~~~~
16111623# struct Point { x: float, y: float }
16121624# struct TuplePoint(float, float);
16131625# mod game { pub struct User { name: &str, age: uint, score: uint } }
1626+ # struct Cookie; fn some_fn<T>(t: T) {}
16141627Point {x: 10f, y: 20f};
16151628TuplePoint(10f, 20f);
16161629let u = game::User {name: "Joe", age: 35u, score: 100_000};
1630+ some_fn::<Cookie>(Cookie);
16171631~~~~
16181632
16191633A structure expression forms a new value of the named structure type.
1634+ Note that for a given * unit-like* structure type, this will always be the same value.
16201635
16211636A structure expression can terminate with the syntax ` .. ` followed by an expression to denote a functional update.
16221637The expression following ` .. ` (the base) must be of the same structure type as the new structure type being formed.
@@ -2643,7 +2658,10 @@ the resulting `struct` value will always be laid out in memory in the order spec
26432658The fields of a ` struct ` may be qualified by [ visibility modifiers] ( #visibility-modifiers ) ,
26442659to restrict access to implementation-private data in a structure.
26452660
2646- A ` tuple struct ` type is just like a structure type, except that the fields are anonymous.
2661+ A _ tuple struct_ type is just like a structure type, except that the fields are anonymous.
2662+
2663+ A _ unit-like struct_ type is like a structure type, except that it has no fields.
2664+ The one value constructed by the associated [ structure expression] ( #structure-expression ) is the only value that inhabits such a type.
26472665
26482666### Enumerated types
26492667
0 commit comments