| Crates.io | interactors |
| lib.rs | interactors |
| version | 0.0.3 |
| created_at | 2025-04-15 14:45:27.768398+00 |
| updated_at | 2025-11-02 14:21:12.786367+00 |
| description | Command pattern implementation for Rust |
| homepage | |
| repository | |
| max_upload_size | |
| id | 1634582 |
| size | 5,395 |
A Rust implementation of the Command Pattern for encapsulating business logic and operations.
This project provides a clean, type-safe implementation of the Command Pattern in Rust. The Command Pattern encapsulates requests as objects, allowing you to:
Command trait with an execute methodCommandInvokeruse interactors::{Command, AddCommand, MultiplyCommand, CommandInvoker};
// Create and execute a command directly
let add_cmd = AddCommand::new(2, 3);
let result = add_cmd.execute().unwrap();
assert_eq!(result, 5);
// Use the command invoker
let multiply_cmd = MultiplyCommand::new(4, 5);
let result = CommandInvoker::invoke(multiply_cmd).unwrap();
assert_eq!(result, 20);
use interactors::Command;
struct GreetCommand {
name: String,
}
impl Command for GreetCommand {
type Output = String;
type Error = std::convert::Infallible;
fn execute(&self) -> Result<Self::Output, Self::Error> {
Ok(format!("Hello, {}!", self.name))
}
}
Add this to your Cargo.toml:
[dependencies]
interactors = "0.0.3"
Licensed under either of:
Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.