1
1
# Use declarations
2
2
3
- > ** <sup >Syntax:<sup >**
3
+ > ** <sup >Syntax:</ sup >**
4
4
> _ UseDeclaration_ :
5
- >   ;  ;   ;  ; ` use ` [ _ SimplePath_ ]   ; (` as ` [ IDENTIFIER] )<sup >?</sup > ` ; `
6
- >   ;  ; | ` use ` ([ _ SimplePath_ ] <sup >?</sup > ` :: ` )<sup >?</sup > ` { ` _ UseDeclarationItems_ ` } ` ` ; `
7
- >   ;  ; | ` use ` ([ _ SimplePath_ ] <sup >?</sup > ` :: ` )<sup >?</sup > ` * ` ` ; `
5
+ >   ;  ; ([ _ Visibility_ ] )<sup >?</sup > ` use ` _ UseTree_ ` ; `
8
6
>
9
- > _ UseDeclarationItems_ :
10
- >   ;  ; _ UseDeclarationItem_ ( ` , ` _ UseDeclarationItem_ )<sup >* </sup > ` , ` <sup >?<sup >
11
- >
12
- > _ UseDeclarationItem_ :
13
- >   ;  ; ( ` self ` | [ IDENTIFIER] ) ( ` as ` [ IDENTIFIER] )<sup >?</sup >
7
+ > _ UseTree_ :
8
+ >   ;  ;   ;  ; ([ _ SimplePath_ ] <sup >?</sup > ` :: ` )<sup >?</sup > ` * `
9
+ >   ;  ; | ([ _ SimplePath_ ] <sup >?</sup > ` :: ` )<sup >?</sup > ` { ` (_ UseTree_ ( ` , ` _ UseTree_ )<sup >* </sup > ` , ` <sup >?</sup >)<sup >?</sup > ` } `
10
+ >   ;  ; | [ _ SimplePath_ ] ` as ` [ IDENTIFIER]
14
11
15
12
A _ use declaration_ creates one or more local name bindings synonymous with
16
13
some other [ path] . Usually a ` use ` declaration is used to shorten the path
@@ -27,16 +24,17 @@ and [blocks], usually at the top.
27
24
28
25
Use declarations support a number of convenient shortcuts:
29
26
30
- * Simultaneously binding a list of paths differing only in their final element,
31
- using the glob-like brace syntax ` use a::b::{c,d,e,f}; `
32
- * Simultaneously binding a list of paths differing only in their final element
33
- and their immediate parent module, using the ` self ` keyword, such as `use
34
- a::b : :{self, c, d};`
27
+ * Simultaneously binding a list of paths with a common prefix, using the
28
+ glob-like brace syntax ` use a::b::{c, d, e::f, g::h::i}; `
29
+ * Simultaneously binding a list of paths with a common prefix and their common
30
+ parent module, using the ` self ` keyword, such as ` use a::b::{self, c, d::e}; `
35
31
* Rebinding the target name as a new local name, using the syntax `use p::q::r
36
- as x;` . This can also be used with the last two features: ` use a: : b : :{self as
37
- ab, c as abc}`.
32
+ as x;`. This can also be used with the last two features:
33
+ ` use a::b::{self as ab, c as abc}` .
38
34
* Binding all paths matching a given prefix, using the asterisk wildcard syntax
39
- ` use a::b::*; `
35
+ ` use a::b::*; ` .
36
+ * Nesting groups of the previous features multiple times, such as
37
+ ` use a::b::{self as ab, c, d::{*, e::f}}; `
40
38
41
39
An example of ` use ` declarations:
42
40
@@ -126,3 +124,4 @@ fn main() {}
126
124
127
125
[ IDENTIFIER ] : identifiers.html
128
126
[ _SimplePath_ ] : paths.html
127
+ [ _Visibility_ ] : visibility-and-privacy.html
0 commit comments