use pedant_core::resolution::rust::RustResolutionSnapshot;
use pedant_types::{Language, ResolutionTier};
use crate::error::GraphBuildError;
use crate::projection::draft::{StatedContainer, UnitPlan};
use crate::projection::placement::SourceIdentity;
use crate::projection::validation as neutral;
use super::validation;
pub(crate) struct SourceKey {
digest: [u8; 32],
tier: ResolutionTier,
language: Language,
vocabulary: Option<StatedContainer>,
source: SourceIdentity,
}
impl SourceKey {
pub(crate) fn stated(
snapshot: &RustResolutionSnapshot,
planned: (&[UnitPlan], u32),
stated: (&SourceIdentity, ResolutionTier),
) -> Result<Self, GraphBuildError> {
let (units, unit) = planned;
let (source, tier) = stated;
let plan = neutral::planned_unit(units, unit)?;
Ok(Self {
digest: validation::source_digest(snapshot, unit, source.path())?,
tier,
language: plan.language,
vocabulary: plan.container.clone(),
source: source.shared(),
})
}
}
impl PartialEq for SourceKey {
fn eq(&self, other: &Self) -> bool {
self.digest == other.digest
&& self.tier == other.tier
&& self.language == other.language
&& self.vocabulary == other.vocabulary
&& self.source == other.source
}
}