Crate storyteller
source ·Expand description
This library is intended to be used by tools, such as cli’s, which have multiple user interface options, through which they can communicate, while also having various separate commands (or flows) which require each to carefully specify their own output formatting.
The library consists of three primary building blocks, and a default implementation on top of these building blocks.
The three building blocks are:
-
EventHandler
: The event handler receives an event (our message type) as input, and decides what to do with this message. Examples include a json-lines handler which prints events to to stderr, a progress bar, a faked handler which collects events for which may be asserted on in software tests, or a handler which sends websocket messages for each event. -
EventReporter
: Used to communicate messages to a user. -
EventListener
: Receives the messages, send by a reporter and runs theEventHandler
where appropriate.
On top of these building blocks, a channel based implementation is provided which runs the EventHandler
in a separate thread.
To use this implementation, consult the docs for the ChannelReporter
,
and the ChannelEventListener
.
Structs
- A listener which uses a channel to receive messages of type
Event
, and uses a thread to run the event handler (inChannelEventListener::run_handler
). - A
FinishProcessing
implementation for theChannelEventListener
. Used to wait for theEventHandler
ran by thelistener
to finish processing events. - A specialized type of reporter which uses a channel to transmit messages.
- A receiver, used by
ChannelReporter
andChannelEventListener
. - A sender, used by
ChannelReporter
andChannelEventListener
.
Enums
Traits
- This can be anything, for example a progress bar, a fake reporter which collects events for testing, a service which sends the events over HTTP, or maybe even a
MultiHandler
which consists of aVec<Box<dyn EventHandler>>
and executes multiple handlers under the hood. - A listener, which listens to events from a
EventReporter
, and can act upon these events by using anEventHandler
. - A reporter (a type of transmitter) which sends events (the message to be transmitted) to a listener (a type of receiver).
- Provides a way for to wait for
EventListener
instances to let theirEventHandler
instances finish up on processing their received events.
Functions
- A channel over which events are sent, from the
ChannelReporter
to theChannelEventListener
.