The use declaration
The use declaration can be used to bind a full path to a new name, for easier
access.
1. // Bind the `deeply::nested::function` path to `other_function`.
2. use deeply::nested::function as other_function;
4. fn function() {
5. println!("called `function()`");
6. }
8. mod deeply {
9. pub mod nested {
10. pub fn function() {
11. println!("called `deeply::nested::function()`");
12. }
13. }
14. }
16. fn main() {
17. // Easier access to `deeply::nested::function`
18. other_function();
20. println!("Entering block");
21. {
22. // This is equivalent to `use deeply::nested::function as function`.
23. // This `function()` will shadow the outer one.
24. use deeply::nested::function;
25. function();
27. // `use` bindings have a local scope. In this case, the
28. // shadowing of `function()` is only in this block.
29. println!("Leaving block");
30. }
32. function();
33. }
