Skip to main content

pedant_types/resolution/
unit.rs

1//! One language compilation and name-resolution context.
2
3use std::sync::Arc;
4
5use serde::{Deserialize, Serialize};
6
7use crate::Language;
8
9use super::id::ResolutionUnitId;
10
11/// One compilation context a report resolves names inside.
12///
13/// Rust maps each unit to one Cargo target instance. `key` is the stable
14/// structural identity a consumer joins on; `name` is what the language calls
15/// the unit.
16#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
17#[serde(deny_unknown_fields)]
18pub struct ResolutionUnit {
19    id: ResolutionUnitId,
20    language: Language,
21    key: Arc<str>,
22    name: Arc<str>,
23}
24
25impl ResolutionUnit {
26    pub(crate) fn new(
27        id: ResolutionUnitId,
28        language: Language,
29        key: Arc<str>,
30        name: Arc<str>,
31    ) -> Self {
32        Self {
33            id,
34            language,
35            key,
36            name,
37        }
38    }
39
40    /// This unit's identifier.
41    pub fn id(&self) -> ResolutionUnitId {
42        self.id
43    }
44
45    /// The language whose resolution rules this unit follows.
46    pub fn language(&self) -> Language {
47        self.language
48    }
49
50    /// The stable structural key units are sorted and deduplicated by.
51    pub fn key(&self) -> &str {
52        &self.key
53    }
54
55    /// The unit's display name.
56    pub fn name(&self) -> &str {
57        &self.name
58    }
59}