use std::fmt;
use std::sync::Arc;
use crate::resolution::rust::dependency::{CargoDependencyKind, DependencyActivation};
use crate::resolution::rust::identity::{PackageId, TargetId};
use crate::resolution::rust::target::CargoTargetKind;
use super::module::RustModuleInstance;
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct RustSnapshotUnitId {
index: u32,
}
impl RustSnapshotUnitId {
pub(super) fn new(index: u32) -> Self {
Self { index }
}
pub(in crate::resolution::rust) fn index(&self) -> u32 {
self.index
}
}
impl fmt::Debug for RustSnapshotUnitId {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(formatter, "RustSnapshotUnitId({})", self.index)
}
}
#[derive(Debug)]
pub struct RustResolutionUnit {
pub(super) id: RustSnapshotUnitId,
pub(super) package: PackageId,
pub(super) target: TargetId,
pub(super) name: Arc<str>,
pub(super) manifest: Arc<str>,
pub(super) kind: CargoTargetKind,
pub(super) activation: DependencyActivation,
pub(super) crate_root: Arc<str>,
pub(super) modules: Box<[RustModuleInstance]>,
pub(super) sources: Box<[Arc<str>]>,
}
impl RustResolutionUnit {
pub fn id(&self) -> RustSnapshotUnitId {
self.id
}
pub fn package(&self) -> PackageId {
self.package
}
pub fn target(&self) -> TargetId {
self.target
}
pub fn name(&self) -> &str {
&self.name
}
pub fn manifest_path(&self) -> &str {
&self.manifest
}
pub fn kind(&self) -> CargoTargetKind {
self.kind
}
pub fn activation(&self) -> &DependencyActivation {
&self.activation
}
pub fn crate_root(&self) -> &str {
&self.crate_root
}
pub fn modules(&self) -> &[RustModuleInstance] {
&self.modules
}
pub fn sources(&self) -> &[Arc<str>] {
&self.sources
}
}
#[derive(Debug)]
pub struct RustSnapshotEdge {
pub(super) source: RustSnapshotUnitId,
pub(super) target: RustSnapshotUnitId,
pub(super) name: Arc<str>,
pub(super) kind: CargoDependencyKind,
pub(super) activation: DependencyActivation,
}
impl RustSnapshotEdge {
pub fn source(&self) -> RustSnapshotUnitId {
self.source
}
pub fn target(&self) -> RustSnapshotUnitId {
self.target
}
pub fn name(&self) -> &str {
&self.name
}
pub fn kind(&self) -> CargoDependencyKind {
self.kind
}
pub fn activation(&self) -> &DependencyActivation {
&self.activation
}
}