A tool to compile SQL to Elasticsearch queries
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

error.rs 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. use std::{error::Error, fmt, fmt::Display};
  2. #[derive(Debug, PartialEq)]
  3. pub struct LexerError {
  4. message: String,
  5. }
  6. impl LexerError {
  7. pub fn new(message: &str) -> Self {
  8. Self {
  9. message: message.to_string(),
  10. }
  11. }
  12. }
  13. impl Display for LexerError {
  14. fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
  15. write!(f, "{}", &self.message)
  16. }
  17. }
  18. impl Error for LexerError {}
  19. impl From<LexerError> for std::io::Error {
  20. fn from(e: LexerError) -> Self {
  21. Self::new(std::io::ErrorKind::InvalidInput, e.message)
  22. }
  23. }
  24. #[derive(Debug, PartialEq)]
  25. pub struct ParserError {
  26. message: String,
  27. }
  28. impl ParserError {
  29. pub fn new(message: &str) -> Self {
  30. Self {
  31. message: message.to_string(),
  32. }
  33. }
  34. }
  35. impl Display for ParserError {
  36. fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
  37. write!(f, "{}", &self.message)
  38. }
  39. }
  40. impl Error for ParserError {}
  41. impl From<ParserError> for std::io::Error {
  42. fn from(e: ParserError) -> Self {
  43. Self::new(std::io::ErrorKind::InvalidInput, e.message)
  44. }
  45. }
  46. #[derive(Debug, PartialEq)]
  47. pub struct CompilerError {
  48. message: String,
  49. }
  50. impl CompilerError {
  51. pub fn new(message: &str) -> Self {
  52. Self {
  53. message: message.to_string(),
  54. }
  55. }
  56. }
  57. impl Display for CompilerError {
  58. fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
  59. write!(f, "{}", &self.message)
  60. }
  61. }
  62. impl Error for CompilerError {}
  63. impl From<CompilerError> for std::io::Error {
  64. fn from(e: CompilerError) -> Self {
  65. Self::new(std::io::ErrorKind::InvalidInput, e.message)
  66. }
  67. }