use super::{
DiagnosticNameRefusal, Observed, Phase, RefusalClass, RenderedMagnitude, SiteCoordinate,
};
use crate::token::{SourceCoordinate, SpanResolutionRefusal};
impl Phase {
pub const ALL: &'static [Self] = &[
Self::Capture,
Self::Planning,
Self::Rendering,
Self::Closure,
Self::Explanation,
Self::Binding,
Self::Assembly,
];
#[must_use]
pub const fn name(self) -> &'static str {
match self {
Self::Capture => "capture",
Self::Planning => "planning",
Self::Rendering => "rendering",
Self::Closure => "closure",
Self::Explanation => "explanation",
Self::Binding => "binding",
Self::Assembly => "assembly",
}
}
}
impl RefusalClass {
pub const ALL: &'static [Self] = &[
Self::DeclarationNotRead,
Self::PlanNotStated,
Self::RenderingNotProduced,
Self::RenderingNotClosed,
Self::ExplanationNotCovered,
Self::MagnitudeNotHeld,
Self::ExpansionNotBound,
Self::CarrierNotAssembled,
Self::CarrierNotDeclared,
];
#[must_use]
pub const fn name(self) -> &'static str {
match self {
Self::DeclarationNotRead => "declaration-not-read",
Self::PlanNotStated => "plan-not-stated",
Self::RenderingNotProduced => "rendering-not-produced",
Self::RenderingNotClosed => "rendering-not-closed",
Self::ExplanationNotCovered => "explanation-not-covered",
Self::MagnitudeNotHeld => "magnitude-not-held",
Self::ExpansionNotBound => "expansion-not-bound",
Self::CarrierNotAssembled => "carrier-not-assembled",
Self::CarrierNotDeclared => "carrier-not-declared",
Self::Declared { name, .. } => name.spelling(),
}
}
#[must_use]
pub const fn described(self) -> &'static str {
match self {
Self::DeclarationNotRead => "the declaration was not read",
Self::PlanNotStated => "planning refused",
Self::RenderingNotProduced => "the renderer did not produce the planned unit",
Self::RenderingNotClosed => {
"the rendering does not close over the plan it claims to materialize"
}
Self::ExplanationNotCovered => "the explanation does not cover its kind's questions",
Self::MagnitudeNotHeld => "a rendering would pass a declared magnitude",
Self::ExpansionNotBound => "the three values do not belong to one expansion",
Self::CarrierNotAssembled => "the closed outputs do not compose into one carrier",
Self::CarrierNotDeclared => "the carrier's own vocabulary was not declared",
Self::Declared { described, .. } => described,
}
}
}
impl Observed {
pub const ALL: &'static [Self] = &[
Self::SeatAbsent,
Self::ContractDisagreement,
Self::IdentityDisagreement,
Self::ProfileDisagreement,
Self::BoundExceeded,
Self::OriginAbsent,
];
#[must_use]
pub const fn name(self) -> &'static str {
match self {
Self::SeatAbsent => "seat-absent",
Self::ContractDisagreement => "contract-disagreement",
Self::IdentityDisagreement => "identity-disagreement",
Self::ProfileDisagreement => "profile-disagreement",
Self::BoundExceeded => "bound-exceeded",
Self::OriginAbsent => "origin-absent",
Self::Declared { name, .. } => name.spelling(),
}
}
}
impl core::fmt::Display for DiagnosticNameRefusal {
fn fmt(&self, into: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
into.write_str(match self {
Self::Empty => "a declared diagnostic name is empty",
Self::NotKebabCase => "a declared diagnostic name is not lowercase ASCII kebab-case",
})
}
}
impl core::error::Error for DiagnosticNameRefusal {}
impl RenderedMagnitude {
pub const ALL: &'static [Self] = &[
Self::RenderedBytes,
Self::RenderedUnits,
Self::GeneratedTokens,
];
#[must_use]
pub const fn name(self) -> &'static str {
match self {
Self::RenderedBytes => "rendered-bytes",
Self::RenderedUnits => "rendered-units",
Self::GeneratedTokens => "generated-tokens",
}
}
#[must_use]
pub const fn described(self) -> &'static str {
match self {
Self::RenderedBytes => "the bytes one rendered unit may carry",
Self::RenderedUnits => "the units one rendering may carry",
Self::GeneratedTokens => "the tokens one generated tree may carry at one nesting level",
}
}
}
impl SiteCoordinate {
#[must_use]
pub const fn answered(answer: Result<SourceCoordinate, SpanResolutionRefusal>) -> Self {
match answer {
Ok(coordinate) => Self::Resolved(coordinate),
Err(refusal) => Self::NotReached(refusal),
}
}
#[must_use]
pub const fn resolved(self) -> Option<SourceCoordinate> {
match self {
Self::Resolved(coordinate) => Some(coordinate),
Self::NotReached(_) => None,
}
}
}