@@ -761,7 +761,9 @@ fn main() {
761
761
##### Export declarations
762
762
763
763
~~~~~~~~ {.ebnf .gram}
764
- export_decl : "export" ident [ ',' ident ] * ;
764
+ export_decl : "export" ident [ ',' ident ] *
765
+ | "export" ident "::{}"
766
+ | "export" ident '{' ident [ ',' ident ] * '}' ;
765
767
~~~~~~~~
766
768
767
769
An _ export declaration_ restricts the set of local names within a module that
@@ -813,6 +815,40 @@ mod foo {
813
815
}
814
816
~~~~~~~~
815
817
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 ` .
816
852
817
853
### Functions
818
854
0 commit comments