Crate paladin_opkind_derive
source ·Expand description
A derive macro for the OpKind trait.
Implementing types MUST be an enum. More specifically, the enum variants MUST be single tuple structs, where the tuple is the type of the operation. For example:
struct OpA;
struct OpB;
struct OpC;
enum MyOps {
OpA(OpA),
OpB(OpB),
OpC(OpC),
}This is what enables a pattern match on the enum to extract the operation.
This construction enables operations to be serialized and executed by a remote service in an opaque manner. In particular, the remote service need not know the exact type of operation, but rather, only the kind of possible operations. This macro takes care of generating the necessary code to facilitate this.
One should consolidate all operations into a single enum, which serves
as the registry of all available operations. The registry should be
exhaustive, in the sense that all possible operations one would like to be
able to execute should be included. This is because the Runtime is
specialized to a single OpKind type, and thus, can only execute operations
defined therein. Of course, you’re free to instantiate multiple Runtime
instances to manage different sets of operations.
Implementation details
This macro does a few things:
- It implements the
OpKindtrait for the enum. - It implements
Fromfor each variant of the enum, allowing you to convert from the operation type to the enum. - It implements
RemoteExecuteforAnyTaskwhere theOpKindis the enum. This is perhaps the most important part of the macro, as it is what enables remote execution of operations. It takes care of deserializing the input, executing the operation, serializing the output, and sending the result back to the receiving channel.
Derive Macros
- See the module level documentation for more information.