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 ///
31 /// # Examples
32 ///
33 /// ```
34 /// use toasty_core::Error;
35 ///
36 /// let err = Error::unsupported_feature("ARRAY type not supported");
37 /// assert!(err.is_unsupported_feature());
38 /// assert_eq!(err.to_string(), "unsupported feature: ARRAY type not supported");
39 /// ```
40 pub fn unsupported_feature(message: impl Into<String>) -> Error {
41 Error::from(super::ErrorKind::UnsupportedFeature(UnsupportedFeature {
42 message: message.into().into(),
43 }))
44 }
45
46 /// Returns `true` if this error is an unsupported feature error.
47 pub fn is_unsupported_feature(&self) -> bool {
48 matches!(self.kind(), super::ErrorKind::UnsupportedFeature(_))
49 }
50}