]> git.lizzy.rs Git - rust.git/blob - src/doc/unstable-book/src/language-features/extern-absolute-paths.md
Rollup merge of #53413 - eddyb:featured-in-the-latest-edition, r=varkor
[rust.git] / src / doc / unstable-book / src / language-features / extern-absolute-paths.md
1 # `extern_absolute_paths`
2
3 The tracking issue for this feature is: [#44660]
4
5 [#44660]: https://github.com/rust-lang/rust/issues/44660
6
7 ------------------------
8
9 The `extern_absolute_paths` feature enables mode allowing to refer to names from other crates
10 "inline", without introducing `extern crate` items, using absolute paths like `::my_crate::a::b`.
11
12 `::my_crate::a::b` will resolve to path `a::b` in crate `my_crate`.
13
14 `feature(crate_in_paths)` can be used in `feature(extern_absolute_paths)` mode for referring
15 to absolute paths in the local crate (`crate::a::b`).
16
17 `feature(extern_in_paths)` provides the same effect by using keyword `extern` to refer to
18 paths from other crates (`extern::my_crate::a::b`).
19
20 ```rust,ignore
21 #![feature(extern_absolute_paths)]
22
23 // Suppose we have a dependency crate `xcrate` available through `Cargo.toml`, or `--extern`
24 // options, or standard Rust distribution, or some other means.
25
26 use xcrate::Z;
27
28 fn f() {
29     use xcrate;
30     use xcrate as ycrate;
31     let s = xcrate::S;
32     assert_eq!(format!("{:?}", s), "S");
33     let z = ycrate::Z;
34     assert_eq!(format!("{:?}", z), "Z");
35 }
36
37 fn main() {
38     let s = ::xcrate::S;
39     assert_eq!(format!("{:?}", s), "S");
40     let z = Z;
41     assert_eq!(format!("{:?}", z), "Z");
42 }
43 ```