use super::types::{
ArtifactMutation, RewriteAdmission, RewriteCandidate, RewriteRoster, RewriteWithheld,
};
use crate::depot::operator_families::OPERATOR_FAMILIES;
use crate::depot::types::OperatorFamily;
use crate::muterprater::{InterpreterAvailability, ScopeShape};
impl ArtifactMutation {
#[must_use]
pub const fn described(self) -> &'static str {
match self {
Self::OrderPermuted => "the emitted members are written in reverse of declared order",
Self::IdentityRecycled => {
"every emitted member is written under the first member's key"
}
Self::PlannedOutputOmitted => "a planned output is deleted",
Self::UnplannedOutputAdded => "an unplanned output is appended",
Self::ImplTargetAltered => "the implementation targets a different type",
Self::ShapeAltered => "the declared body shape is changed",
Self::OutputDuplicated => "a planned output is emitted twice",
Self::TraitPathWrong => "the trait path names a different contract",
Self::DecoyInComment => "the anchored bytes are planted in a comment",
Self::ImplMemberDuplicated => "one member constant is emitted twice",
Self::ImplMemberUnexpected => "a member nobody planned joins the implementation",
Self::ConstructorPathAltered => "a row is built through another constructor",
Self::ImplPostureAltered => "the implementation is written under another posture",
Self::MeaningBearingAttributeAdded => "an attribute that decides something is added",
Self::MalformedRust => "the artifact stops being well-formed Rust",
}
}
}
#[must_use]
pub fn planned(roster: &RewriteRoster, scope: &ScopeShape) -> Vec<RewriteCandidate> {
roster
.descriptors()
.iter()
.map(|descriptor| RewriteCandidate::planned(*descriptor, scope.clone()))
.collect()
}
#[must_use]
pub fn admission<Input, Meaning>(
interpreter: &InterpreterAvailability<'_, '_, '_, '_, '_, '_, Input, Meaning>,
) -> RewriteAdmission {
match interpreter {
InterpreterAvailability::Available(_) => RewriteAdmission::Admitted,
InterpreterAvailability::NoConformingSurface => {
RewriteAdmission::Withheld(RewriteWithheld::InterpreterUnavailable)
}
InterpreterAvailability::TrustNotOpened { missing } => {
RewriteAdmission::Withheld(RewriteWithheld::TrustNotOpened(*missing))
}
}
}
#[must_use]
pub fn unrealized_families(roster: &RewriteRoster) -> Vec<OperatorFamily> {
OPERATOR_FAMILIES
.iter()
.copied()
.filter(|family| {
!roster
.descriptors()
.iter()
.any(|descriptor| descriptor.family().slug() == family.slug())
})
.collect()
}