use std::{
error::Error,
fmt::{Display, Error as FmtError, Formatter},
};
include!(concat!(env!("OUT_DIR"), "/features.rs"));
#[derive(Clone, Copy, Debug)]
pub struct FeatureRestrictionError {
pub feature: &'static str,
pub restriction: FeatureRestriction,
}
impl Error for FeatureRestrictionError {}
impl Display for FeatureRestrictionError {
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), FmtError> {
write!(
f,
"a restriction for the feature {} was not met: {}",
self.feature, self.restriction,
)
}
}
#[derive(Clone, Copy, Debug)]
pub enum FeatureRestriction {
NotSupported,
RequiresFeature(&'static str),
ConflictsFeature(&'static str),
RequiredByExtension(&'static str),
}
impl Display for FeatureRestriction {
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), FmtError> {
match *self {
FeatureRestriction::NotSupported => {
write!(f, "not supported by the physical device")
}
FeatureRestriction::RequiresFeature(feat) => {
write!(f, "requires feature {} to be enabled", feat)
}
FeatureRestriction::ConflictsFeature(feat) => {
write!(f, "requires feature {} to be disabled", feat)
}
FeatureRestriction::RequiredByExtension(ext) => {
write!(f, "required to be enabled by extension {}", ext)
}
}
}
}