[][src]Trait kompact::prelude::Port

pub trait Port {
    type Indication: Sized + Send + 'static + Clone + Debug;
    type Request: Sized + Send + 'static + Clone + Debug;
}

A Kompact port specifies the API of an abstraction

Such an API consists of requests, which are events handled by a provider component, and indications, which are events triggered by providers and handled by components that require the abstraction.

All events on ports must be safe to send between threads, and must be cloneable, as multiple components may be connected to a single port, in which case each component will receive its own copy of the event. For types that are expensive to clone, but read-only, the usage of an Arc is recommended.

Example

Consider an abstraction that sums up numbers it is given, and can be asked to provide the current total.

use kompact::prelude::*;

#[derive(Clone, Debug)]
struct Sum(u64);

#[derive(Clone, Debug)]
enum SumRequest {
    Number(u64),
    Query   
}

struct SummerPort;
impl Port for SummerPort {
    type Indication = Sum;
    type Request = SumRequest;
}

Associated Types

type Indication: Sized + Send + 'static + Clone + Debug

Indications are triggered by provider components (see Provide) and handled by requiring components (see Require).

type Request: Sized + Send + 'static + Clone + Debug

Requests are triggered by requiring components (see Require) and handled by provider components (see Provide).

Loading content...

Implementors

impl Port for TestPort[src]

impl Port for ControlPort[src]

Loading content...