typed_use_cases 0.1.0

Formalize use cases at the type level. Zero runtime overhead. Experimental proof-of-concept.
Documentation
/// Marks a type as an actor — the initiator of a use case.
/// Actors exist independently of any entity or action.
pub trait Actor {}

/// Marks a type as a domain entity — what a use case operates on.
pub trait Entity {}

/// A domain entity whose existence is tied to a specific actor.
/// Extends Entity and adds ownership semantics.
pub trait DependentEntity<A: Actor>: Entity {
    fn owner(&self) -> &A;
}

/// The central trait. A UseCase IS an action.
/// A: the actor that initiates it.
/// E: the entity it operates on.
pub trait UseCase<A: Actor, E: Entity> {
    /// Human-readable name of the use case.
    const NAME: &'static str;

    /// Human-readable description of the use case.
    const DESCRIPTION: &'static str;

    /// Data the use case receives as input (beyond the actor and entity).
    /// Use () if no additional input is needed.
    type Input;

    /// What the use case produces.
    type Output;

    /// External services or dependencies the use case needs to execute.
    /// Use () if no dependencies are needed.
    /// Can be a concrete type, a trait bound, or a tuple of services.
    type Dependencies;

    /// Defines how the use case satisfies its contract.
    /// This is a compile-time witness that the use case structure exists.
    /// The implementation shows what the use case does conceptually,
    /// but this is NOT meant to be called at runtime in production.
    fn satisfy(
        actor: A,
        entity: E,
        input: Self::Input,
        deps: Self::Dependencies,
    ) -> Self::Output;
}