Macro rustfbp::component
[−]
[src]
macro_rules! component { ( $name:ident, $( contracts( $( $contract:ident ),* ) )* inputs($( $input_field_name:ident: $input_contract_name:ident),* ), inputs_array($( $input_array_name:ident: $input_contract_array:ident),* ), outputs($( $output_field_name:ident: $output_contract_name:ident),* ), outputs_array($($output_array_name:ident: $output_contract_array:ident),* ), option($($option_contract: ident),*), acc($($acc_contract: ident),*), $( portal($portal_type:ty => $portal_value:expr))* fn run(&mut $arg:ident) -> Result<()> $fun:block ) => { ... }; }
The component macro.
It helps to define a component, by defining the input and output ports, if there is an option or an acc port, ...
contracts()
and portal()
are optional.
Example :
component! { display, contract(generic_text) inputs(input: any), inputs_array(), outputs(output: any), outputs_array(), option(generic_text), acc() 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.get_root()); // 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(()) } }Run