Macro rustfbp::agent [] [src]

macro_rules! agent {
    (
       $name:ident, $( edges( $( $edge:ident ),* ) )*
        inputs($( $input_field_name:ident: $input_edge_name:ident),* ),
        inputs_array($( $input_array_name:ident: $input_edge_array:ident),* ),
        outputs($( $output_field_name:ident: $output_edge_name:ident),* ),
        outputs_array($($output_array_name:ident: $output_edge_array:ident),* ),
        option($($option_edge: ident),*),
        acc($($acc_edge: ident),*), $( portal($portal_type:ty => $portal_value:expr))*
        fn run(&mut $arg:ident) -> Result<()> $fun:block
    ) => { ... };
}

The agent macro.

It helps to define a agent, by defining the input and output ports, if there is an option or an acc port, ...

edges() and portal() are optional.

Example :

agent! {
   display, edges(generic_text)
   inputs(input: any),
   inputs_array(),
   outputs(output: any),
   outputs_array(),
   option(generic_text),
   acc(), portal()
   fn run(&mut self) -> Result<()> {
       // Receive an IP
       let ip = try!(self.ports.recv("input"));

       // Received an IP from the option port (a generic_text)
       let opt = self.recv_opt();

       // Get the capn'p reader
       let reader: generic_text::Reader = try!(opt.read_schema());
       // Print the option
       println!("{}", try!(reader.get_text()));

       // Send the received IP outside, but don't care about the success (drop on fail)
       let _ = self.ports.send("output", ip);

       Ok(())
   }
}