1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
use super::Error;
/// Error when a driver's capability configuration is invalid or inconsistent.
///
/// This occurs when:
/// - Driver capability flags are inconsistent (e.g., native_varchar=true but varchar type not specified)
/// - Required capability fields are missing or contradictory
///
/// These errors indicate a programming error in the driver implementation itself,
/// not a user error or runtime condition.
#[derive(Debug)]
pub(super) struct InvalidDriverConfiguration {
message: Box<str>,
}
impl std::error::Error for InvalidDriverConfiguration {}
impl core::fmt::Display for InvalidDriverConfiguration {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
write!(f, "invalid driver configuration: {}", self.message)
}
}
impl Error {
/// Creates an invalid driver configuration error.
///
/// This is used when a driver's capability configuration is invalid or inconsistent.
/// These errors indicate a bug in the driver implementation.
///
/// # Examples
///
/// ```
/// use toasty_core::Error;
///
/// let err = Error::invalid_driver_configuration("inconsistent capability flags");
/// assert!(err.is_invalid_driver_configuration());
/// ```
pub fn invalid_driver_configuration(message: impl Into<String>) -> Error {
Error::from(super::ErrorKind::InvalidDriverConfiguration(
InvalidDriverConfiguration {
message: message.into().into(),
},
))
}
/// Returns `true` if this error is an invalid driver configuration error.
pub fn is_invalid_driver_configuration(&self) -> bool {
matches!(self.kind(), super::ErrorKind::InvalidDriverConfiguration(_))
}
}