What is the meaning of `use path :: {self}`?

I recently read the following line of code :

use fmt::{self, Debug}; 

What does the self keyword mean in the above expression?

+5
source share
2 answers

Using self in this context allows you to associate a module with some of its children in the current scope with a single use statement.

Without yourself:

 use a::b::{c,d}; // Now you can refer to a::b::c as c and a::b::d as d // but if you need to refer to a::b as a::b 

With itself:

 use a::b::{self, c, d}; // Now b refers to a::b as well 
+6
source

self here refers to the module itself, i.e. your line is equivalent to two lines

 use fmt::Debug; use fmt; 
+8
source

Source: https://habr.com/ru/post/1275796/


All Articles