pub struct RequiredPort<P>where
P: Port + 'static,{ /* private fields */ }Expand description
An instance of a port type P that is marked as required
Any component C that holds an instance of a required port for P
must also implement Require<P>.
§Example
use kompact::prelude::*;
struct UnitPort;
impl Port for UnitPort {
type Indication = ();
type Request = ();
}
#[derive(ComponentDefinition, Actor)]
struct UnitRequirer {
ctx: ComponentContext<Self>,
unit_port: RequiredPort<UnitPort>,
}
impl UnitRequirer {
fn new() -> UnitRequirer {
UnitRequirer {
ctx: ComponentContext::uninitialised(),
unit_port: RequiredPort::uninitialised(),
}
}
}
ignore_lifecycle!(UnitRequirer);
impl Require<UnitPort> for UnitRequirer {
fn handle(&mut self, event: ()) -> HandlerResult {
Handled::OK // handle event
}
}Implementations§
Source§impl<P> RequiredPort<P>where
P: Port + 'static,
impl<P> RequiredPort<P>where
P: Port + 'static,
Sourcepub fn uninitialised() -> RequiredPort<P>
pub fn uninitialised() -> RequiredPort<P>
Create a new required port for port type P
§Note
This port instance can only be used after the parent component has been created, and not during the constructor or anywhere else!
Sourcepub fn trigger(&mut self, event: <P as Port>::Request)
pub fn trigger(&mut self, event: <P as Port>::Request)
Trigger event on this port.
Only requests events can be triggered on required ports.
Triggered events will be cloned for each connected channel.
Sourcepub fn connect(&mut self, c: ProvidedRef<P>)
pub fn connect(&mut self, c: ProvidedRef<P>)
Connect to a provided port reference
Port references are acquired via the share function.
Sourcepub fn disconnect_port(&mut self, c: ProvidedRef<P>) -> bool
pub fn disconnect_port(&mut self, c: ProvidedRef<P>) -> bool
Remove the given port from our connection list
Returns true if the connections changed,
i.e. when c was present.
Sourcepub fn disconnect_component(&mut self, c: &dyn CoreContainer) -> bool
pub fn disconnect_component(&mut self, c: &dyn CoreContainer) -> bool
Removes all ports owned by component c from our connection list
Returns true if the connections changed,
i.e. when at least one port was owned by c.
Share a reference to this port to connect to
Ports are connected to references via the connect function.
Sourcepub fn set_parent(&mut self, p: Arc<dyn CoreContainer>)
pub fn set_parent(&mut self, p: Arc<dyn CoreContainer>)
Mark p as the parent component of this port
This method should only be used in custom ComponentDefinition implementations!
Sourcepub fn dequeue(&self) -> Option<<P as Port>::Indication>
pub fn dequeue(&self) -> Option<<P as Port>::Indication>
Take the first element off the queue, if any
This method should only be used in custom ComponentDefinition implementations!