pub trait UseCase:
Send
+ Sync
+ Send {
type Input: Send;
type Output: Send;
type Error: Error + Send + Sync + 'static;
// Required method
fn execute(
&self,
input: Self::Input,
) -> impl Future<Output = Result<Self::Output, Self::Error>> + Send;
}Expand description
A single, named application operation that orchestrates domain objects and ports to do one thing.
§Examples
use ddd_toolkit_core::application::usecase::UseCase;
use std::fmt::Display;
#[derive(Debug)]
struct GreetError;
impl Display for GreetError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "name must not be empty")
}
}
impl std::error::Error for GreetError {}
struct Greet;
impl UseCase for Greet {
type Input = String;
type Output = String;
type Error = GreetError;
async fn execute(&self, input: Self::Input) -> Result<Self::Output, Self::Error> {
if input.trim().is_empty() {
return Err(GreetError);
}
Ok(format!("hello, {input}"))
}
}
let greeting = block_on(Greet.execute("world".to_string()))?;
assert_eq!(greeting, "hello, world");
assert!(block_on(Greet.execute(String::new())).is_err());Required Associated Types§
Required Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".