Skip to content

Commit cd9b344

Browse files
committed
Update docs to reflect new export forms
1 parent 368daf8 commit cd9b344

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

doc/rust.md

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,9 @@ fn main() {
761761
##### Export declarations
762762

763763
~~~~~~~~ {.ebnf .gram}
764-
export_decl : "export" ident [ ',' ident ] * ;
764+
export_decl : "export" ident [ ',' ident ] *
765+
| "export" ident "::{}"
766+
| "export" ident '{' ident [ ',' ident ] * '}' ;
765767
~~~~~~~~
766768

767769
An _export declaration_ restricts the set of local names within a module that
@@ -813,6 +815,40 @@ mod foo {
813815
}
814816
~~~~~~~~
815817

818+
When exporting the name of an `enum` type `t`, by default, the module also
819+
implicitly exports all of `t`'s constructors. For example:
820+
821+
~~~~~~~~
822+
mod foo {
823+
export t;
824+
825+
enum t {a, b, c};
826+
}
827+
~~~~~~~~
828+
829+
Here, `foo` imports `t`, `a`, `b`, and `c`.
830+
831+
The second and third forms of export declaration can be used to export
832+
an `enum` item without exporting all of its constructors. These two
833+
forms can only be used to export an `enum` item. The second form
834+
exports the `enum` type name without exporting any of its
835+
constructors, achieving a simple kind of data abstraction. The third
836+
form exports an `enum` type name along with a subset of its
837+
constructors. For example:
838+
839+
~~~~~~~~
840+
mod foo {
841+
export abstract{};
842+
export slightly_abstract{a, b};
843+
844+
enum abstract {x, y, z}
845+
enum slightly_abstract {a, b, c, d}
846+
}
847+
~~~~~~~~
848+
849+
Module `foo` exports the types `abstract` and `slightly_abstract`, as well as
850+
constructors `a` and `b`, but doesn't export constructors `x`, `y`, `z`, `c`,
851+
or `d`.
816852

817853
### Functions
818854

0 commit comments

Comments
 (0)