Skip to main content

RequiredPort

Struct RequiredPort 

Source
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,

Source

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!

Source

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.

Source

pub fn connect(&mut self, c: ProvidedRef<P>)

Connect to a provided port reference

Port references are acquired via the share function.

Source

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.

Source

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.

Source

pub fn share(&mut self) -> RequiredRef<P>

Share a reference to this port to connect to

Ports are connected to references via the connect function.

Source

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!

Source

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!

Auto Trait Implementations§

§

impl<P> Freeze for RequiredPort<P>

§

impl<P> !RefUnwindSafe for RequiredPort<P>

§

impl<P> Send for RequiredPort<P>

§

impl<P> Sync for RequiredPort<P>

§

impl<P> Unpin for RequiredPort<P>

§

impl<P> UnsafeUnpin for RequiredPort<P>

§

impl<P> !UnwindSafe for RequiredPort<P>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> Erased for T