【发布时间】:2015-05-03 02:40:38
【问题描述】:
我刚开始学习 Rust,但自从更新到 beta 版本后,我遇到了许多以前没有的编译错误。
其中之一与clone 有关,这是我的代码:
use std::io::{BufReader, BufRead};
use std::clone::Clone;
use std::env;
use std::fs::File;
pub fn main() {
let ref path = match env::args().nth(1) {
Some(path) => path,
None => panic!("file path is missing!"), };
let file = match File::open(&path) {
Ok(file) => file,
Err(_) => panic!("could not open {}", path), };
let mut iter = BufReader::new(file).lines();
let mut opt = iter.next();
let str = opt.clone().unwrap().unwrap();
// some code omitted
}
这是错误:
test.rs:19:19: 19:26 错误:类型
core::option::Option<core::result::Result<collections::string::String, std::io::error::Error>>未在名为clone的范围内实现任何方法 test.rs:19 let str = opt.clone().unwrap().unwrap();
我需要clone,因为我在代码的其他部分使用了opt。
是我的代码有问题,还是在 Rust 中发生了一些我不知道的更改?
【问题讨论】:
标签: compiler-errors rust