`use path :: {self}`是什么意思?

Gre*_*ree 5 self rust

我最近阅读了以下代码行:

use fmt::{self, Debug}; 
Run Code Online (Sandbox Code Playgroud)

self上述声明中的关键字是什么意思?

fjh*_*fjh 8

self 这里指的是模块本身,即你的线相当于两条线

use fmt::Debug;
use fmt;
Run Code Online (Sandbox Code Playgroud)


har*_*mic 6

self在该上下文中使用允许您使用单个use语句将模块及其部分子元素绑定到当前作用域中.

没有自我:

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
Run Code Online (Sandbox Code Playgroud)

有了自己:

use a::b::{self, c, d};
// Now b refers to a::b as well
Run Code Online (Sandbox Code Playgroud)