Update docs to reflect new export forms

This commit is contained in:
Tim Chevalier 2012-01-23 16:28:56 -08:00
parent 368daf8b5a
commit cd9b344f7b
1 changed files with 37 additions and 1 deletions

View File

@ -761,7 +761,9 @@ fn main() {
##### Export declarations
~~~~~~~~ {.ebnf .gram}
export_decl : "export" ident [ ',' ident ] * ;
export_decl : "export" ident [ ',' ident ] *
| "export" ident "::{}"
| "export" ident '{' ident [ ',' ident ] * '}' ;
~~~~~~~~
An _export declaration_ restricts the set of local names within a module that
@ -813,6 +815,40 @@ mod foo {
}
~~~~~~~~
When exporting the name of an `enum` type `t`, by default, the module also
implicitly exports all of `t`'s constructors. For example:
~~~~~~~~
mod foo {
export t;
enum t {a, b, c};
}
~~~~~~~~
Here, `foo` imports `t`, `a`, `b`, and `c`.
The second and third forms of export declaration can be used to export
an `enum` item without exporting all of its constructors. These two
forms can only be used to export an `enum` item. The second form
exports the `enum` type name without exporting any of its
constructors, achieving a simple kind of data abstraction. The third
form exports an `enum` type name along with a subset of its
constructors. For example:
~~~~~~~~
mod foo {
export abstract{};
export slightly_abstract{a, b};
enum abstract {x, y, z}
enum slightly_abstract {a, b, c, d}
}
~~~~~~~~
Module `foo` exports the types `abstract` and `slightly_abstract`, as well as
constructors `a` and `b`, but doesn't export constructors `x`, `y`, `z`, `c`,
or `d`.
### Functions