mnesis 0.1.0

A zero-compromise event-sourcing and CQRS kernel for Rust with maximum compile-time type safety
Documentation
/// Aggregate::Error must implement std::error::Error.
/// A plain enum without #[derive(Error)] should fail.

use mnesis::*;

#[derive(Debug, Clone)]
enum MyEvent { A }
impl Message for MyEvent {}
impl DomainEvent for MyEvent {
    fn name(&self) -> &'static str { "A" }
}

#[derive(Default, Debug, Clone)]
struct MyState;
impl AggregateState for MyState {
    type Event = MyEvent;
    fn initial() -> Self { Self::default() }
    fn apply(self, _: &MyEvent) -> Self { self }
}

// This error does NOT implement std::error::Error
#[derive(Debug)]
enum BadError {
    Something,
}

#[derive(Debug)]
struct MyAggregate;

impl Aggregate for MyAggregate {
    type State = MyState;
    type Error = BadError; // should fail: BadError doesn't impl Error
    type Id = MyId;
}

#[derive(Debug, Clone, Hash, PartialEq, Eq)]
struct MyId(String);
impl MyId {
    fn new(v: u64) -> Self { Self(v.to_string()) }
}
impl std::fmt::Display for MyId {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.0) }
}
impl AsRef<[u8]> for MyId {
    fn as_ref(&self) -> &[u8] { self.0.as_bytes() }
}

fn main() {}