From 6aa63ff07ad637d143acc4ce492f9fc1fcc510fc Mon Sep 17 00:00:00 2001 From: ChristianVisintin Date: Fri, 27 Nov 2020 15:33:55 +0100 Subject: [PATCH] std::fmt::Display for HostError --- src/host/mod.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/host/mod.rs b/src/host/mod.rs index d47478e..e05ac9a 100644 --- a/src/host/mod.rs +++ b/src/host/mod.rs @@ -72,6 +72,24 @@ impl HostError { } +impl std::fmt::Display for HostError { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + let code_str: &str = match self.error { + HostErrorType::NoSuchFileOrDirectory => "No such file or directory", + HostErrorType::ReadonlyFile => "File is readonly", + HostErrorType::DirNotAccessible => "Could not access directory", + HostErrorType::FileNotAccessible => "Could not access directory", + HostErrorType::FileAlreadyExists => "File already exists", + HostErrorType::CouldNotCreateFile => "Could not create file", + HostErrorType::DeleteFailed => "Could not delete file", + }; + match self.ioerr { + Some(err) => write!(f, "{}: {}", code_str, err), + None => write!(f, "{}", code_str) + } + } +} + /// ## Localhost /// /// Localhost is the entity which holds the information about the current directory and host.