Crate presage

Source
Expand description

§Présage \pʁe.zaʒ\

Présage is a Rust lightweight library for designing event-based systems.

§Concepts

In an event-based systems, anything that can happen is modeled with an Event. Business entities are designed with aggregates, that are atomically modified with events.

Présage is freely inspired by concepts like domain-driven design or command-query responsibility segregation, but tries to be agnostic by making as few assumptions as possible. Specifically, it does not tie you to any persistence approach.

§Command bus

The command bus is the main entry point when using présage. It takes a context and a command to execute. The resulting events are persisted, then any matching event handler is executed. Those event handlers can return new commands which are also executed. The process continues as long as events and commands are issued.

§Context

Command handlers and event handlers are executed within a mutable context. This context is specific to your application and contains whatever is necessary for the execution of the handlers. For instance, it can contain a connection to a database.

§Features

The derive feature, which is enabled by default, provides derive macros for Event, AggregateEvent and Command, as well as attribute macros to easily create command handlers and event handlers.

Macros§

commands
Creates a new Commands containing the commands passed as arguments.
events
Creates a new Events containing the events passed as arguments.

Structs§

BoxedCommand
A command that has been boxed to be dispatched.
CommandBus
Executes a command and handles issued events.
Commands
Wrapper for a Vec of boxed commands.
Configuration
A configuration for a CommandBus.
Events
Wrapper for a Vec of serialized events.
Id
Wrapper type for the id of an aggregate.
SerializedEvent
An event that has been serialized to be issued by a command.

Enums§

Error
Errors that can occur during the execution of a command by a CommandBus.

Traits§

Aggregate
An aggregate represent a business entity that can evolve during the system execution.
AggregateEvent
An Event that creates, updates, or deletes an aggregate.
Command
A request to modify the system.
CommandHandler
Handles a command and produces events.
Event
An event represent something that happened in the past.
EventHandler
Reacts to issued events.
EventWriter
Persists the modifications of events.

Attribute Macros§

async_traitderive
command_handlerderive
Creates an CommandHandler from a function.
event_handlerderive
Creates an EventHandler from a function.

Derive Macros§

AggregateEventderive
Derives the AggregateEvent trait.
Commandderive
Derives the Command trait.
Eventderive
Derives the Event trait.