use super::internal::supports_conversion;
use crate::DataType;
#[must_use]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct ConversionCapabilities {
private: (),
}
impl ConversionCapabilities {
#[inline]
pub const fn current() -> Self {
Self { private: () }
}
#[must_use]
#[inline]
pub const fn is_available(self, data_type: DataType) -> bool {
match data_type {
DataType::Date | DataType::Time | DataType::DateTime | DataType::Instant => {
cfg!(feature = "chrono")
}
DataType::BigInteger => cfg!(feature = "big-integer"),
DataType::BigDecimal => cfg!(feature = "big-decimal"),
DataType::Url => cfg!(feature = "url"),
DataType::Json => cfg!(feature = "json"),
DataType::Bool
| DataType::Char
| DataType::Int8
| DataType::Int16
| DataType::Int32
| DataType::Int64
| DataType::Int128
| DataType::UInt8
| DataType::UInt16
| DataType::UInt32
| DataType::UInt64
| DataType::UInt128
| DataType::Float32
| DataType::Float64
| DataType::String
| DataType::Duration
| DataType::StringMap => true,
}
}
#[must_use]
pub fn supports(self, from: DataType, to: DataType) -> bool {
if !self.is_available(from) || !self.is_available(to) {
return false;
}
supports_conversion(from, to)
}
#[must_use = "the supported target iterator must be consumed"]
#[inline]
pub fn supported_targets(self, from: DataType) -> impl Iterator<Item = DataType> {
DataType::ALL.iter().copied().filter(move |to| self.supports(from, *to))
}
}