use std::sync::Arc;
use pedant_types::ReferenceKind;
use super::denotation::Denotation;
use super::implementations::{Implementations, Relation};
use super::index::Index;
pub(super) fn of_unit(
index: &Index,
implementations: &Implementations,
unit: usize,
) -> Vec<Denotation> {
implementations
.of_unit(unit)
.filter_map(|relation| implementation(index, relation))
.collect()
}
fn implementation(index: &Index, relation: &Relation) -> Option<Denotation> {
let concrete = index.slot(relation.concrete.slot())?;
Some(Denotation {
kind: ReferenceKind::Implementation,
text: implementing_form(&concrete.name, relation.pointer),
span: concrete.site.clone(),
enclosing: Some(relation.concrete.slot()),
candidates: Box::from([relation.interface.slot()]),
gap: relation.gap,
conditional: concrete.conditional,
possible_only: relation.gap.is_some(),
})
}
fn implementing_form(name: &Arc<str>, pointer: bool) -> Arc<str> {
match pointer {
true => Arc::from(format!("*{name}")),
false => Arc::clone(name),
}
}