//! The refusal codes of §2.1 and §2.7, the render request errors of §2.7, and where a //! refusal was found. //! //! The code is normative: two conforming sinks that hold the same bytes report the same //! one. The step and the rule are this implementation's diagnostics. #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] pub enum Code { PayloadMalformed, TooLarge, FieldRange, PointsLimit, OutlineNotHeld, OutlineMismatch, OutlineMalformed, GlyphMissing, GeometryRange, /// Render request errors (§2.7, *Render*): not refusals of the payload. SizeUnlisted, RateUnlisted, FrameRange, } pub const CODES: [Code; 12] = [ Code::PayloadMalformed, Code::TooLarge, Code::FieldRange, Code::PointsLimit, Code::OutlineNotHeld, Code::OutlineMismatch, Code::OutlineMalformed, Code::GlyphMissing, Code::GeometryRange, Code::SizeUnlisted, Code::RateUnlisted, Code::FrameRange, ]; impl Code { pub const fn name(self) -> &'static str { match self { Code::PayloadMalformed => "payload_malformed", Code::TooLarge => "too_large", Code::FieldRange => "field_range", Code::PointsLimit => "points_limit", Code::OutlineNotHeld => "outline_not_held", Code::OutlineMismatch => "outline_mismatch", Code::OutlineMalformed => "outline_malformed", Code::GlyphMissing => "glyph_missing", Code::GeometryRange => "geometry_range", Code::SizeUnlisted => "size_unlisted", Code::RateUnlisted => "rate_unlisted", Code::FrameRange => "frame_range", } } pub fn from_name(s: &str) -> Option { CODES.iter().copied().find(|c| c.name() == s) } } /// A refusal: its code, the §2.7 (or §2.1) step that found it, the rule, and the /// record index the rule failed at (0 where none applies). #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub struct Refusal { pub code: Code, pub step: &'static str, pub rule: &'static str, pub index: u64, } impl Refusal { pub const fn new(code: Code, step: &'static str, rule: &'static str, index: u64) -> Refusal { Refusal { code, step, rule, index } } } pub(crate) const fn refuse(code: Code, step: &'static str, rule: &'static str, index: u64) -> Result { Err(Refusal::new(code, step, rule, index)) }