use默认情况下,Rust似乎有些命名空间.例如,我不必使用std::string::String,只需键入即可String.我怎样才能定义自己struct String而不与之发生冲突std::string::String?我在哪里可以找到默认包含的命名空间列表?
你可以创建自己String的...创建自己的字符串:
struct String {
len: u8,
}
fn main() {}
Run Code Online (Sandbox Code Playgroud)
然后,您可以String使用完全限定的路径消除所需的歧义:
fn main() {
// String::new();
// error: type `String` does not implement any method in scope named `new`
std::string::String::new();
}
Run Code Online (Sandbox Code Playgroud)
自动导入项目的完整列表可以在序言中找到(版本1,在撰写本文时).