/src/errors.rs

https://gitlab.com/saruman9/rust-understand · Rust · 105 lines · 102 code · 2 blank · 1 comment · 4 complexity · 1ffe4a5f6f603afc0e2886a61409de0b MD5 · raw file

  1. use std::fmt;
  2. // TODO udbStatusText(status: UdbStatus) -> *const c_char - ?
  3. pub enum StatusError {
  4. DBAlreadyOpen,
  5. DBBusy,
  6. DBChanged,
  7. DBCorrupt,
  8. DBOldVersion,
  9. DBUnknownVersion,
  10. DBUnableCreate,
  11. DBUnableDelete,
  12. DBUnableModify,
  13. DBUnableOpen,
  14. DBUnableWrite,
  15. DemoAnotherDBOpen,
  16. DemoInvalid,
  17. DrawNoFont,
  18. DrawNoImage,
  19. DrawTooBig,
  20. DrawUnableCreateFile,
  21. DrawUnsupportedFile,
  22. LexerFileModified,
  23. LexerFileUnreadable,
  24. LexerUnsupportedLanguage,
  25. NoApiLicense,
  26. NoApiLicenseAda,
  27. NoApiLicenseC,
  28. NoApiLicenseCobol,
  29. NoApiLicenseFtn,
  30. NoApiLicenseJava,
  31. NoApiLicenseJovial,
  32. NoApiLicensePascal,
  33. NoApiLicensePlm,
  34. NoApiLicensePython,
  35. NoApiLicenseWeb,
  36. NoApiLicenseVhdl,
  37. NoApiLicenseVerilog,
  38. ReportUnableCreate,
  39. ReportUnableDelete,
  40. ReportUnableWrite,
  41. UserAbort,
  42. WrongProduct,
  43. }
  44. impl StatusError {
  45. pub fn __description(&self) -> &str {
  46. match *self {
  47. StatusError::DBAlreadyOpen => "database already open",
  48. StatusError::DBBusy => "database busy",
  49. StatusError::DBChanged => "database changed",
  50. StatusError::DBCorrupt => "database corrupt",
  51. StatusError::DBOldVersion => "old version of database",
  52. StatusError::DBUnknownVersion => "unknown version of database",
  53. StatusError::DBUnableCreate => "unable to create database",
  54. StatusError::DBUnableDelete => "unable to delete database",
  55. StatusError::DBUnableModify => "unable to modify database",
  56. StatusError::DBUnableOpen => "unable to open database",
  57. StatusError::DBUnableWrite => "unable to write database",
  58. StatusError::DemoAnotherDBOpen => "Demo: another database open",
  59. StatusError::DemoInvalid => "Demo: invalid",
  60. StatusError::DrawNoFont => "Draw: no font",
  61. StatusError::DrawNoImage => "Draw: no image",
  62. StatusError::DrawTooBig => "Draw: too big for draw",
  63. StatusError::DrawUnableCreateFile => "Draw: unable to create file",
  64. StatusError::DrawUnsupportedFile => "Draw: unsupported file",
  65. StatusError::LexerFileModified => "Lexer: file modified",
  66. StatusError::LexerFileUnreadable => "Lexer: file unreadable",
  67. StatusError::LexerUnsupportedLanguage => "Lexer: unsupported language",
  68. StatusError::NoApiLicense => "API: no license",
  69. StatusError::NoApiLicenseAda => "API: no license Ada",
  70. StatusError::NoApiLicenseC => "API: no license C",
  71. StatusError::NoApiLicenseCobol => "API: no license COBOL",
  72. StatusError::NoApiLicenseFtn => "API: no license FORTRAN",
  73. StatusError::NoApiLicenseJava => "API: no license Java",
  74. StatusError::NoApiLicenseJovial => "API: no license Jovial",
  75. StatusError::NoApiLicensePascal => "API: no license Pascal",
  76. StatusError::NoApiLicensePlm => "API: no license PL/M",
  77. StatusError::NoApiLicensePython => "API: no license Python",
  78. StatusError::NoApiLicenseWeb => "API: no license web",
  79. StatusError::NoApiLicenseVhdl => "API: no license VHDL",
  80. StatusError::NoApiLicenseVerilog => "API: no license Verilog",
  81. StatusError::ReportUnableCreate => "Report: unable create",
  82. StatusError::ReportUnableDelete => "Report: unable delete",
  83. StatusError::ReportUnableWrite => "Report: unable write",
  84. StatusError::UserAbort => "abort by user",
  85. StatusError::WrongProduct => "wrong product",
  86. }
  87. }
  88. }
  89. impl fmt::Display for StatusError {
  90. fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
  91. self.__description().fmt(f)
  92. }
  93. }
  94. impl fmt::Debug for StatusError {
  95. fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
  96. write!(f, "{}", self.__description())
  97. }
  98. }
  99. impl ::std::error::Error for StatusError {
  100. fn description(&self) -> &str {
  101. self.__description()
  102. }
  103. }