error.rs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. use std::fmt::{Debug, Display, Formatter};
  2. use nix::errno::Errno;
  3. pub struct NixError {
  4. errno: Errno
  5. }
  6. impl Debug for NixError {
  7. fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
  8. Debug::fmt(&self.errno, f)
  9. }
  10. }
  11. impl Display for NixError {
  12. fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
  13. Display::fmt(&self.errno, f)
  14. }
  15. }
  16. impl std::error::Error for NixError {
  17. }
  18. impl From<Errno> for NixError {
  19. fn from(value: Errno) -> Self {
  20. Self{
  21. errno: value,
  22. }
  23. }
  24. }
  25. pub struct ExecError {
  26. err_msg: String
  27. }
  28. impl ExecError {
  29. pub fn from_str(s: &str) -> Self {
  30. Self{
  31. err_msg: s.to_string()
  32. }
  33. }
  34. }
  35. impl Debug for ExecError {
  36. fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
  37. write!(f, "{}", self.err_msg)
  38. }
  39. }
  40. impl Display for ExecError {
  41. fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
  42. write!(f, "{}", self.err_msg)
  43. }
  44. }
  45. impl std::error::Error for ExecError {
  46. }
  47. impl From<std::io::Error> for ExecError {
  48. fn from(value: std::io::Error) -> Self {
  49. Self{
  50. err_msg: format!("IO Error: {:?}", value)
  51. }
  52. }
  53. }