Expand description
Derive macros for Behaviors.
There are 4 derive macros available:
- Action
- Condition
- Control
- Decorator
On struct level there are the attributes
#[behavior(no_create)]: will suppress the derive of create_fn(…)#[behavior(no_register)]: will suppress the derive of register()#[behavior(no_register_with)]: will suppress the derive of register_with(…)#[behavior(groot2)]: marks the behavior as one that is internally known to Groot2
On field level there are the attributes
#[behavior(parameter)]: defines a field as a parameter forcreate_fn(...)andregister_with(...)The values must be given when using theregister_with(...)method. A parameter must implementClone.#[behavior(default = <Expression>)]: defines a default value for a field. ‘Expression’ can be any Rust expression that creates an appropriate value out of nothing.#[behavior(parameter, default = <Expression>)]: combines both. The field is a parameter ofcreate_fn(...)andregister_with(...), and ‘Expression’ provides the value that the parameterlessregister()passes for it instead ofDefault::default().#[behavior(portlist)]: marks the field that holds the behavior’s port list. This attribute cannot be combined with any other attribute.
Fields without any of these attributes are initialised with Default::default().
§Usage
Example uses the derive macro Action, the others work respectively.
#[derive(Action)]
struct MyAction {
// specific elements
...
}
impl MyAction {
// your specific implementations
...
}§Errors
- if used on anything other than a struct
- if used on a struct with unnamed fields
- if attributes are used in a wrong way