From abae21527aaab63460af17825b477877a8b46933 Mon Sep 17 00:00:00 2001 From: Mathieu David Date: Thu, 13 Aug 2015 10:00:44 +0200 Subject: [PATCH] Copied the PathExt trait from the rust source code as temporary fix. Now I can replace the hacky code I used. When it goes to rust stable I will just have to remove and eventually change some --- src/utils/mod.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 5a7c1fd0..3551de29 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -2,6 +2,27 @@ use std::path::{Path, PathBuf, Component}; use std::error::Error; use std::fs::{self, metadata, File}; +/// This is copied from the rust source code until Path_ Ext stabilizes. +/// You can use it, but be aware that it will be removed when those features go to rust stable +pub trait PathExt { + fn exists(&self) -> bool; + fn is_file(&self) -> bool; + fn is_dir(&self) -> bool; +} + +impl PathExt for Path { + fn exists(&self) -> bool { + metadata(self).is_ok() + } + + fn is_file(&self) -> bool { + metadata(self).map(|s| s.is_file()).unwrap_or(false) + } + + fn is_dir(&self) -> bool { + metadata(self).map(|s| s.is_dir()).unwrap_or(false) + } +} /// Takes a path and returns a path containing just enough `../` to point to the root of the given path. ///