Path
を読み取り、DirEntry
のインスタンスを返す関数を書いています。私が理解していない奇妙な行動があります。あなたのコード例でRustで奇妙なパスの振る舞いを理解できません
pub fn file_to_direntry<T: AsRef<Path>>(filepath: T) -> Result<DirEntry, Box<Error>> {
match filepath.has_parent() {
Some(parent) => {
//..
}
// has no parent
// this line would cause an error
// Err(Error { repr: Os { code: 2, message: "No such file or directory" } })
None => path_to_entry(Path::new("."), path),
}
}
fn path_to_entry<A: AsRef<Path>, B: AsRef<Path>>(path: A, filename: B) -> Result<DirEntry, Box<Error>> {
let filename: &Path = filename.as_ref();
let path: &Path = path.as_ref();
// this line prints, "" "."
println!("{:?} {:?}", path, PathBuf::from("."));
// when I replace this line to
// for entry in try!(read_dir(PathBuf::from(".")))
// it works perfectly fine
for entry in try!(read_dir(path)) {
println!("{:?}", try!(entry));
}
Err(From::from("no file found"))
}
Full code on the Rust playground
右が、エラーは削除ライン32&追加されたコメントの後にライン31 – Interaction
でスローされ、https://play.rust-lang.org/?gist=fa07e627043890122ca31fba9b31a96c&version=stable&backtrace=0 – Interaction
私はあなたの新しいリンクが含まれて質問。 – ljedrz