use pedant_core::resolution::rust::{
RustResolutionSnapshot, RustSnapshotUnitId, RustTargetResolution, RustUnitBinding,
};
use pedant_types::ResolutionUnit;
use crate::error::GraphBuildError;
use crate::projection::validation as neutral;
pub(crate) fn check_root_target(
snapshot: &RustResolutionSnapshot,
resolution: &RustTargetResolution,
) -> Result<(), GraphBuildError> {
match snapshot.root_target() == resolution.root_target() {
true => Ok(()),
false => Err(GraphBuildError::RootTargetMismatch),
}
}
pub(crate) fn check_snapshot_identity(
snapshot: &RustResolutionSnapshot,
resolution: &RustTargetResolution,
) -> Result<(), GraphBuildError> {
neutral::matching_fingerprint(snapshot.fingerprint(), resolution.snapshot_fingerprint())
}
pub(crate) fn stated_binding(
resolution: &RustTargetResolution,
unit: &ResolutionUnit,
) -> Result<RustSnapshotUnitId, GraphBuildError> {
resolution
.unit(unit.id())
.map(RustUnitBinding::snapshot_unit)
.ok_or(GraphBuildError::MissingUnitBinding {
unit: unit.id().index(),
})
}
pub(crate) fn source_digest(
snapshot: &RustResolutionSnapshot,
unit: u32,
path: &str,
) -> Result<[u8; 32], GraphBuildError> {
snapshot
.source(path)
.map(|source| *source.digest())
.ok_or_else(|| GraphBuildError::MissingSourceNode {
unit,
path: Box::from(path),
})
}