Crate p4_macro

Source
Expand description

The use_p4! macro allows for P4 programs to be directly integrated into Rust programs.

p4_macro::use_p4!("path/to/p4/program.p4");

This will generate a main_pipeline struct that implements the Pipeline trait. The use_p4! macro expands directly in to x4c compiled code. This includes all data structures, parsers and control blocks.

To customize the name of the generated pipeline use the pipeline_name parameter.

p4_macro::use_p4!(p4 = "path/to/p4/program.p4", pipeline_name = "muffin");

This will result in a muffin_pipeline struct being being generated.

For documentation on using Pipeline trait, see the p4rs docs.

Macros§

use_p4
The use_p4! macro uses the x4c compiler to generate Rust code from a P4 program. The macro itself expands into the generated code. The macro can be called with only the path to the P4 program as an argument or, it can be called with the path to the P4 program plus the name to use for the generated pipeline object.