toasty_core/error/unsupported_feature.rs
1use super::Error;
2
3/// Error when a database does not support a requested feature.
4///
5/// This occurs when:
6/// - A statement type is not supported by the database (unsupported primitive type)
7/// - A storage type is not available (VARCHAR not supported)
8/// - A feature constraint is exceeded (VARCHAR size exceeds database limit)
9///
10/// These errors are typically caught during schema construction or validation,
11/// indicating a mismatch between application requirements and database capabilities.
12#[derive(Debug)]
13pub(super) struct UnsupportedFeature {
14 message: Box<str>,
15}
16
17impl std::error::Error for UnsupportedFeature {}
18
19impl core::fmt::Display for UnsupportedFeature {
20 fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
21 write!(f, "unsupported feature: {}", self.message)
22 }
23}
24
25impl Error {
26 /// Creates an unsupported feature error.
27 ///
28 /// This is used when a database does not support a requested feature,
29 /// such as a specific type, storage constraint, or capability.
30 pub fn unsupported_feature(message: impl Into<String>) -> Error {
31 Error::from(super::ErrorKind::UnsupportedFeature(UnsupportedFeature {
32 message: message.into().into(),
33 }))
34 }
35
36 /// Returns `true` if this error is an unsupported feature error.
37 pub fn is_unsupported_feature(&self) -> bool {
38 matches!(self.kind(), super::ErrorKind::UnsupportedFeature(_))
39 }
40}