Skip to main content

proto_package

Macro proto_package 

Source
proto_package!() { /* proc-macro */ }
Expand description

Creates a new package handle, which is used to collect the proto schemas in a crate.

For a comprehensive guide of how to set up a package, visit the package setup section.

The first parameter of the macro is the ident that will be used for the generated constant that will hold the package handle, which will be used to generate the package and its proto files.

To distinguish the package handle from a normal rust type, it is advised to use SCREAMING_CASE casing.

The other parameters are not positional and are as follows:

  • name (required)
    • Type: string

    • Example: proto_package!(MY_PKG, name = "my_pkg")

    • Description: The name of the package.

    • no_cel_test

    • Type: Ident

    • Example: proto_package!(MY_PKG, name = "my_pkg", no_cel_test)

    • Description: By default, if the cel feature is enabled, the macro will automatically generate a test that will check for collisions of CEL rules with the same ID within the same message. You can use this ident to disable this behaviour. The check_unique_cel_rules method will still be available if you want to call it manually inside a test.

As explained in the package setup section, when the inventory feature is disabled, the files of a given package must be added manually, inside a bracketed list.

ยงExamples

use protify::*;

// If we want to skip the automatically generated
// Test for conflicting CEL rules in the same scope
proto_package!(WITHOUT_TEST, name = "without_test", no_cel_test);

// If the `inventory` feature is disabled, we add the files manually
proto_package!(MY_PKG, name = "my_pkg", files = [ MY_FILE ]);
define_proto_file!(MY_FILE, name = "my_file.proto", package = MY_PKG);