mysql_connector/error/
parse.rs1use {
2 super::ProtocolError,
3 crate::types::{Value, ValueType},
4 std::{fmt, str::Utf8Error, string::FromUtf8Error},
5};
6
7pub struct WrongValue(pub ValueType, pub Value);
8
9impl fmt::Debug for WrongValue {
10 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
11 f.debug_struct("WrongValue")
12 .field("expected", &self.0)
13 .field("got", &self.1)
14 .finish()
15 }
16}
17
18#[derive(Debug)]
19pub enum InvalidFlags {
20 Status(u16),
21 Capability(u32),
22 CursorType(u8),
23 StmtExecuteParams(u8),
24 StmtExecuteParam(u8),
25 Column(u16),
26 ColumnType(u8),
27}
28
29#[derive(Debug)]
30pub enum ParseError {
31 MissingField(&'static str),
32 RowLengthMismatch,
33 WrongValue(WrongValue),
34 InvalidValue(ValueType, Vec<u8>),
35 ValueOutOfBounds(Value),
36 UnknownBitflags(InvalidFlags),
37 Utf8(Utf8Error),
38 FromUtf8(FromUtf8Error),
39}
40
41impl ParseError {
42 pub fn wrong_value(expected: ValueType, got: Value) -> Self {
43 Self::WrongValue(WrongValue(expected, got))
44 }
45}
46
47impl From<InvalidFlags> for ParseError {
48 fn from(value: InvalidFlags) -> Self {
49 ParseError::UnknownBitflags(value)
50 }
51}
52
53impl From<InvalidFlags> for ProtocolError {
54 fn from(value: InvalidFlags) -> Self {
55 ParseError::UnknownBitflags(value).into()
56 }
57}
58
59impl From<Utf8Error> for ParseError {
60 fn from(value: Utf8Error) -> Self {
61 ParseError::Utf8(value)
62 }
63}
64
65impl From<Utf8Error> for ProtocolError {
66 fn from(value: Utf8Error) -> Self {
67 ParseError::Utf8(value).into()
68 }
69}
70
71impl From<FromUtf8Error> for ParseError {
72 fn from(value: FromUtf8Error) -> Self {
73 ParseError::FromUtf8(value)
74 }
75}
76
77impl From<FromUtf8Error> for ProtocolError {
78 fn from(value: FromUtf8Error) -> Self {
79 ParseError::FromUtf8(value).into()
80 }
81}