Skip to content

Commit 43945e6

Browse files
committed
---
yaml --- r: 7651 b: refs/heads/master c: cd9b344 h: refs/heads/master i: 7649: f5a6558 7647: 9a62adf v: v3
1 parent 6b701d7 commit 43945e6

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 368daf8b5a0df49e75bca21d8f7a0af87b387230
2+
refs/heads/master: cd9b344f7b5fe93c52ea7cbce83b21d776fd0b8e

trunk/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)