Target Handler
Target Handler provides a derive macro to easily create a handler struct for
an enum with multiple variants. The idea is to transform or avoid a match
construct into a trait with a handler function for each variant the enum has.
The target handler was implemented to simplify or beautify the handling of a
clap Subcommands enum as seen in this
example.
But it may be useful for other purposes or as a hint on how to implement some
design patterns, like Command or Message Broker in rust (though this is
neither of them and much simpler).
Example
use Target;
// The enum for which a handler shall be implemented. The macro will create a
// trait 'MessageHandler', which must be implemented by the handler struct.
// After implementing the trait, an arbitrary message can be handled using the
// 'deliver' method. If the 'returns' attribute is set, all handlers must
// implement the specified return type, as will the 'deliver' method.
;
// The trait enforces an implementation of a handler method for every enum
// variant and delivers in turn a default implementation for the summarized
// handler method.