use crate::{design::prelude::*, traits::Validator};
#[validator]
pub struct MaxDecimalPlaces {
target: u32,
}
impl MaxDecimalPlaces {
pub fn new(target: impl TryInto<u32>) -> Self {
Self {
target: target.try_into().unwrap_or_default(),
}
}
}
impl Validator<Decimal> for MaxDecimalPlaces {
fn validate(&self, n: &Decimal, ctx: &mut dyn VisitorContext) {
if n.scale() > self.target {
ctx.issue(Issue::DecimalScaleMax {
actual: n.scale(),
max: self.target,
});
}
}
}