很难在文档中找到它.这可能是一个两部分问题:
是{integer}和{float}特定原始类型的某种语言别名?
在编译/语法错误消息中用大括号括起类型名称是什么意思?
例:
错误:没有为当前范围中的
pow类型命名的方法{integer}
我在使用Iterator'sflat_map函数时遇到了困难,我不太确定如何理解和解决这个编译器错误。
我通过序列化两个结构将文件路径列表 flat_mapping 成两个字符串:
let body: Vec<String> = read_dir(query.to_string())
.iter()
.enumerate()
.flat_map(|(i, path)| {
let mut body: Vec<String> = Vec::with_capacity(2);
let entry = Entry { i };
body.push(serde_json::to_string(&entry).unwrap());
let record = parse_into_record(path.to_string()).unwrap();
body.push(serde_json::to_string(&record).unwrap());
body.iter()
})
.collect();
Run Code Online (Sandbox Code Playgroud)
error[E0277]: a value of type `std::vec::Vec<std::string::String>` cannot be built from an iterator over elements of type `&std::string::String`
--> src/main.rs:275:10
|
275 | .collect();
| ^^^^^^^ value of type `std::vec::Vec<std::string::String>` cannot be built from `std::iter::Iterator<Item=&std::string::String>`
|
= help: the trait `std::iter::FromIterator<&std::string::String>` …Run Code Online (Sandbox Code Playgroud) 我正在玩一些代码,并做了以下观察:
let x = 1;
let () = x;
error: mismatched types [E0308]
note: expected type `_`
note: found type `()`
Run Code Online (Sandbox Code Playgroud)
这显然失败了,但我期待错误说明预期的类型i32不是_.我发现同样的情况发生在一个未指定类型的浮动文字中,例如1.0.
为什么会这样?这种类型不应该被称为默认类型吗?
更新:从Rust 1.12开始,错误消息提供更多信息:
expected integral variable, found ()
= note: expected type `{integer}`
= note: found type `()`
Run Code Online (Sandbox Code Playgroud)