#[derive(Clone, Debug)]
pub(crate) struct BindingSlot {
pub slot: String,
pub role: String,
pub concrete_type_name: String,
pub storage_types: Vec<(&'static str, &'static bb_ir::types::TypeNode)>,
}
impl BindingSlot {
pub(crate) fn storage_type_opt(&self, port: &str) -> Option<&'static bb_ir::types::TypeNode> {
self.storage_types
.iter()
.find(|(k, _)| *k == port)
.map(|(_, t)| *t)
}
}
#[derive(Clone, Debug, Default)]
pub(crate) struct BindingSpec {
pub slots: Vec<BindingSlot>,
}
impl BindingSpec {
pub(crate) fn new() -> Self {
Self::default()
}
pub(crate) fn push(
&mut self,
slot: impl Into<String>,
role: impl Into<String>,
concrete: impl Into<String>,
) {
self.slots.push(BindingSlot {
slot: slot.into(),
role: role.into(),
concrete_type_name: concrete.into(),
storage_types: Vec::new(),
});
}
pub(crate) fn push_with_storage(
&mut self,
slot: impl Into<String>,
role: impl Into<String>,
concrete: impl Into<String>,
storage_types: Vec<(&'static str, &'static bb_ir::types::TypeNode)>,
) {
self.slots.push(BindingSlot {
slot: slot.into(),
role: role.into(),
concrete_type_name: concrete.into(),
storage_types,
});
}
pub(crate) fn get(&self, slot: &str) -> Option<&BindingSlot> {
self.slots.iter().find(|s| s.slot == slot)
}
pub(crate) fn lookup_by_role(&self, role: &str) -> Option<&BindingSlot> {
self.slots.iter().find(|s| s.role == role)
}
}