use std::collections::HashMap;
pub type ItemResolutionTable = HashMap<String, String>;
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct Remap {
interface: Option<String>,
item_resolution_table: ItemResolutionTable,
}
impl Remap {
pub fn found_as(interface: impl Into<String>) -> Self {
Self {
interface: Some(interface.into()),
item_resolution_table: HashMap::new(),
}
}
pub fn resolves_item(
requested_item: impl Into<String>,
exported_item: impl Into<String>,
) -> Self {
Self {
interface: None,
item_resolution_table: HashMap::from([(requested_item.into(), exported_item.into())]),
}
}
pub fn item_resolution_table(item_resolution_table: ItemResolutionTable) -> Self {
Self {
interface: None,
item_resolution_table,
}
}
pub fn found_as_with_item_resolution_table(
interface: impl Into<String>,
item_resolution_table: ItemResolutionTable,
) -> Self {
Self {
interface: Some(interface.into()),
item_resolution_table,
}
}
pub(crate) fn interface_name<'a>( &'a self, requested_interface: &'a str ) -> &'a str {
self.interface.as_deref().unwrap_or( requested_interface )
}
pub(crate) fn item_name<'a>( &'a self, requested_item: &'a str ) -> &'a str {
self.item_resolution_table
.get( requested_item )
.map_or( requested_item, String::as_str )
}
}