Attribute Macro zbus_lockstep_macros::validate
source · #[validate]
Expand description
Validate a struct’s type signature against XML signal body type.
Retrieves the signal body type from a (collection of) XML file(s) and compares it to the struct’s type signature.
If the XML file(s) are found in the default location, xml/
or XML/
of the crate root,
or provided as environment variable, LOCKSTEP_XML_PATH
, the macro can be used without
arguments.
§Arguments
#[validate]
can take three optional arguments:
xml
: Path to XML file(s) containing the signal definition.interface
: Interface name of the signal.signal
: Signal name.
#[validate(xml: <xml_path>, interface: <interface_name>, member: <member_name>)]
§xml_path
Without an argument, the macro looks for XML file(s) in xml/
or XML/
of the crate root.
If the definitions are to be found elsewhere, there are two options:
Use the xml
argument:
#[validate(xml: "xml")]
#[derive(Type)]
struct RemoveNodeSignal {
name: String,
path: OwnedObjectPath,
}
Alternatively, you can provide the XML directory path as environment variable,
LOCKSTEP_XML_PATH
, which will override both default and the path argument.
§interface
If more than one signal with the same name is defined in the XML file(s), the macro will fail and you can provide an interface name to disambiguate.
#[validate(interface: "org.example.Node")]
#[derive(Type)]
struct RemoveNodeSignal {
name: String,
path: OwnedObjectPath,
}
§signal
If a custom signal name is desired, you can be provided using signal:
.
#[validate(signal: "RemoveNode")]
#[derive(Type)]
struct RemoveNodeSignal {
name: String,
path: OwnedObjectPath,
}
§Multiple arguments
You can provide multiple arguments with a comma separated list.
§Examples
#[validate(xml: "xml", interface: "org.example.Node", signal: "RemoveNode")]
#[derive(Type)]
struct RemoveNodeSignal {
name: String,
path: OwnedObjectPath,
}