Explorar el Código

Implement Display and std::error::Error for AskError.

Kestrel hace 1 semana
padre
commit
a6a37a931c
Se han modificado 2 ficheros con 29 adiciones y 1 borrados
  1. 1 1
      Cargo.toml
  2. 28 0
      src/lib.rs

+ 1 - 1
Cargo.toml

@@ -7,7 +7,7 @@ keywords = ["cli", "input", "prompt", "ask", "interactive"]
 license = "LGPL-3.0-only"
 name = "cliask"
 repository = "https://git.flying-kestrel.ca/kestrel/cliask"
-version = "0.1.0"
+version = "0.1.1"
 
 [dependencies]
 cliask-derive = { path = "derive", version = "0.1.0" }

+ 28 - 0
src/lib.rs

@@ -30,6 +30,34 @@ pub enum AskError {
     IOError(std::io::Error),
 }
 
+impl std::fmt::Display for AskError {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        <AskError as std::fmt::Debug>::fmt(self, f)
+    }
+}
+
+impl std::error::Error for AskError {
+    #[allow(deprecated)]
+    fn cause(&self) -> Option<&dyn std::error::Error> {
+        match self {
+            Self::IOError(e) => e.cause()
+        }
+    }
+
+    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
+        match self {
+            Self::IOError(e) => e.source()
+        }
+    }
+
+    #[allow(deprecated)]
+    fn description(&self) -> &str {
+        match self {
+            Self::IOError(e) => e.description()
+        }
+    }
+}
+
 impl From<std::io::Error> for AskError {
     fn from(value: std::io::Error) -> Self {
         Self::IOError(value)