1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
//! # typed_use_cases
//!
//! **Formalize use cases at the type level. Zero runtime overhead.**
//!
//! A Rust library that brings UML use cases into your type system, providing compile-time
//! awareness when your code structure changes in ways that affect declared use cases.
//!
//! > ⚠️ **Experimental**: This is a proof-of-concept library. It has not been validated in
//! > production environments and should be considered an exploratory tool for representing
//! > use cases in type systems.
//!
//! ## Quick Example
//!
//! ```rust
//! use typed_use_cases::{Actor, Entity, UseCase};
//!
//! // Define actors
//! #[derive(Actor)]
//! struct Authenticated { user_id: u64 }
//!
//! // Define entities
//! #[derive(Entity)]
//! struct Cart { owner: Authenticated, items: Vec<u64> }
//!
//! // Declare a use case
//! trait AddItemToCart: UseCase<
//! Authenticated,
//! Cart,
//! Input = u64,
//! Output = Cart,
//! Dependencies = (),
//! > {}
//!
//! // Define your System type (application-specific, not part of this library)
//! struct System;
//!
//! // Implement the use case
//! impl UseCase<Authenticated, Cart> for System {
//! const NAME: &'static str = "Add item to cart";
//! const DESCRIPTION: &'static str = "User adds product to their cart";
//!
//! type Input = u64;
//! type Output = Cart;
//! type Dependencies = ();
//!
//! fn satisfy(
//! actor: Authenticated,
//! mut cart: Cart,
//! product_id: u64,
//! _deps: (),
//! ) -> Cart {
//! cart.items.push(product_id);
//! cart
//! }
//! }
//!
//! impl AddItemToCart for System {}
//!
//! // Verify at compile time (in tests only)
//! # #[cfg(test)]
//! typed_use_cases::implement_all_use_cases!(System: [AddItemToCart]);
//! ```
//!
//! ## What This Library Does
//!
//! - **Formalizes use cases** as named traits in Rust
//! - **Compile-time awareness**: The compiler knows which use cases exist
//! - **Breaking changes are visible**: If you change a method signature, the compiler breaks at the use case level
//! - **Zero runtime overhead**: Uses a zero-sized System type (0 bytes)
//! - **Verification in tests only**: Uses `#[cfg(test)]` to verify implementations
//!
//! ## What This Library Is NOT
//!
//! - ❌ **NOT a verification tool** - Does not prove your program satisfies a use case
//! - ❌ **NOT a testing framework** - Does not test that your system fulfills requirements
//! - ❌ **NOT a formal methods tool** - Does not prove program properties
//! - ❌ **NOT for runtime enforcement** - All verification happens at compile time
//!
//! ## Installation
//!
//! Using cargo:
//!
//! ```bash
//! cargo add typed_use_cases
//! ```
//!
//! Or in `Cargo.toml`:
//!
//! ```toml
//! [dependencies]
//! typed_use_cases = "0.1"
//! ```
//!
//! ## Core Concepts
//!
//! - [`Actor`] - The initiator of a use case (e.g., `Authenticated`, `Anonymous`)
//! - [`Entity`] - What the use case operates on (e.g., `Cart`, `Order`)
//! - [`DependentEntity`] - An entity owned by a specific actor
//! - [`UseCase`] - The central trait representing an action
//! - [`implement_all_use_cases!`] - Macro to verify all use cases are implemented
pub use ;
pub use ;