diff --git a/src/runtime2/inbox.rs b/src/runtime2/inbox.rs index 1260a183ef590ff04c7fd96b068a795795d9565d..9175a2239cf60bb154e70b9e28c11d94d1d02fe4 100644 --- a/src/runtime2/inbox.rs +++ b/src/runtime2/inbox.rs @@ -42,7 +42,7 @@ impl BranchMarker { } /// The header added by the synchronization algorithm to all. -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Copy)] pub(crate) struct SyncHeader { pub sending_component_id: ConnectorId, pub highest_component_id: ConnectorId, @@ -164,6 +164,32 @@ impl Message { Message::Control(_) => return None, } } + + /// If the message is sent through a particular channel, then this function + /// returns the target port through which the message was sent. + pub(crate) fn target_port(&self) -> Option { + match self { + Message::Data(message) => return Some(message.data_header.target_port), + Message::SyncPort(message) => return Some(message.target_port), + Message::SyncComp(_) => return None, + Message::SyncControl(_) => return None, + Message::Control(message) => { + match &message.content { + ControlContent::PortPeerChanged(port_id, _) => return Some(*port_id), + ControlContent::CloseChannel(port_id) => return Some(*port_id), + ControlContent::Ping => return None, + ControlContent::Ack => return None, + } + } + } + } + + pub(crate) fn as_data(&self) -> &DataMessage { + match self { + Message::Data(v) => v, + _ => unreachable!(), + } + } } /// The public inbox of a connector. The thread running the connector that owns