use crate::resolution::rust::resolve::{RustTargetResolution, RustUnitBinding};
use crate::resolution::rust::snapshot::RustSnapshotUnitId;
pub fn resolution_without_unit_binding(
resolution: &RustTargetResolution,
) -> Option<RustTargetResolution> {
let bound = resolution.units().len().checked_sub(1)?;
let units: Box<[RustUnitBinding]> = resolution.units().iter().copied().take(bound).collect();
Some(resolution.with_unit_bindings(units))
}
pub fn resolution_with_swapped_unit_sources(
resolution: &RustTargetResolution,
) -> Option<RustTargetResolution> {
let (first, second) = leading_snapshot_units(resolution.units())?;
let mut units: Vec<RustUnitBinding> = resolution.units().to_vec();
units[0] = units[0].rebound(second);
units[1] = units[1].rebound(first);
Some(resolution.with_unit_bindings(units.into_boxed_slice()))
}
pub fn resolution_with_shared_unit_binding(
resolution: &RustTargetResolution,
) -> Option<RustTargetResolution> {
let (first, _) = leading_snapshot_units(resolution.units())?;
let mut units: Vec<RustUnitBinding> = resolution.units().to_vec();
units[1] = units[1].rebound(first);
Some(resolution.with_unit_bindings(units.into_boxed_slice()))
}
fn leading_snapshot_units(
units: &[RustUnitBinding],
) -> Option<(RustSnapshotUnitId, RustSnapshotUnitId)> {
match units {
[first, second, ..] => Some((first.snapshot_unit(), second.snapshot_unit())),
_ => None,
}
}