summary refs log tree commit diff
path: root/src/path
diff options
context:
space:
mode:
Diffstat (limited to 'src/path')
-rw-r--r--src/path/error.rs28
-rw-r--r--src/path/prelude.rs5
2 files changed, 33 insertions, 0 deletions
diff --git a/src/path/error.rs b/src/path/error.rs
index 0ee5423..aee6e9f 100644
--- a/src/path/error.rs
+++ b/src/path/error.rs
@@ -1,3 +1,10 @@
+#![forbid(unsafe_code)]
+
+use crate::path::GenericPath;
+
+pub type Result<T> = std::result::Result<T, PathError>;
+
+
 #[derive(Clone,Debug,Eq,Hash,Ord,PartialEq,PartialOrd)]
 pub enum FileNameError {
   ContainsSlash(String),
@@ -11,6 +18,10 @@ pub enum DirectoryNameError {
 #[derive(Clone,Debug,Eq,Hash,Ord,PartialEq,PartialOrd)]
 pub enum PathError {
   Parse(String),
+  PathLexicallyDirectory(GenericPath),
+  PathLexicallyRelative(GenericPath),
+  PathLexicallyInvalid(GenericPath),
+  PathListHasEmptyComponents(String),
 }
 
 
@@ -45,6 +56,23 @@ impl std::fmt::Display for PathError {
     match self {
       PathError::Parse(s) =>
         f.write_fmt(format_args!("Syntax error in path: {}", s)),
+      PathError::PathLexicallyDirectory(path) =>
+        f.write_fmt(format_args!(
+            "The path {} ends in a slash, but is supposed to refer to a file, \
+             not a directory.",
+            path)),
+      PathError::PathLexicallyRelative(path) =>
+        f.write_fmt(format_args!(
+            "The path {} is relative, not absolute.",
+            path)),
+      PathError::PathLexicallyInvalid(path) =>
+        f.write_fmt(format_args!(
+            "This isn't a valid path. {}",
+            path)),
+      PathError::PathListHasEmptyComponents(path_list) =>
+        f.write_fmt(format_args!(
+            "Path list has empty components: {}",
+            path_list)),
     }
   }
 }
diff --git a/src/path/prelude.rs b/src/path/prelude.rs
new file mode 100644
index 0000000..f7b23dd
--- /dev/null
+++ b/src/path/prelude.rs
@@ -0,0 +1,5 @@
+#![forbid(unsafe_code)]
+
+pub use crate::path::error::{
+    Result, DirectoryNameError, FileNameError, PathError};
+