use super::{BINDING_FACT, BindError};
use crate::bounded::Bounded;
use crate::diagnostic::{
BINDING_FAMILY, Family, LineBody, Observed, Phase, REPAIR_LIMIT, RefusalClass, Refused, Repair,
};
use crate::identity::human_projection;
use core::fmt;
impl BindError {
#[must_use]
pub const fn slot(&self) -> u8 {
match self {
Self::ClosureProvedAgainstAnotherPlan { .. } => 0,
Self::ExplanationAnsweredOverAnotherPlan { .. } => 1,
Self::ExplanationAnsweredOverAnotherClosure { .. } => 2,
}
}
}
impl fmt::Display for BindError {
fn fmt(&self, into: &mut fmt::Formatter<'_>) -> fmt::Result {
into.write_str(match self {
Self::ClosureProvedAgainstAnotherPlan { .. } => {
"the closure proves a rendering against a plan other than the one bound beside it"
}
Self::ExplanationAnsweredOverAnotherPlan { .. } => {
"the explanation was answered over a plan other than the one bound beside it"
}
Self::ExplanationAnsweredOverAnotherClosure { .. } => {
"the explanation was answered over a proof other than the one bound beside it"
}
})
}
}
impl core::error::Error for BindError {}
impl Refused for BindError {
const PHASE: Phase = Phase::Binding;
const FAMILY: Family = BINDING_FAMILY;
fn class(&self) -> RefusalClass {
RefusalClass::ExpansionNotBound
}
fn first(&self) -> String {
self.to_string()
}
fn observed(&self) -> Observed {
Observed::IdentityDisagreement
}
fn body(&self) -> LineBody {
LineBody::SingleCause
}
fn related(&self) -> Vec<Vec<u8>> {
Vec::new()
}
fn repairs(&self) -> Bounded<Repair, REPAIR_LIMIT> {
Bounded::from_array([Repair {
declared_by: BINDING_FACT,
description: human_projection!(
"an expansion binds the plan its proof was taken against and the explanation answered over the two, so a proof or an explanation belonging to another expansion is refused rather than bound under one identity"
),
}])
}
}