How to check for a path in Rust 1.1?

In Rust 1.1, std::fs::PathExt marked unstable; How to check for a file or directory?

Is there a canonical solution for this, or do I need to read the source std::fs::PathExt ?

Maybe a box that provides this functionality?

+5
source share
1 answer

PathExt - simple wrappers around std::fs::metadata ; if the path does not exist, metadata will return an error, therefore PathExt.exists() is a simple metadata(self).is_ok() .

Usually you should use is_file or is_dir ; they correspond to metadata(self).map(|m| m.Β«is_file or is_dirΒ»()).unwrap_or(false) .

+1
source

All Articles