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
//! Provides the [`OnceCommand`] trait for implementing executable commands.
//!
//! This module defines a simple command pattern where commands consume themselves
//! on execution, ensuring they can only be run once. This is useful for CLI
//! subcommands that perform side effects like file creation.
/// A command that consumes itself when executed.
///
/// This trait provides a clean abstraction for CLI subcommands, ensuring that
/// each command instance can only be executed once. The consuming `self` parameter
/// prevents accidental re-execution.
///
/// # Type Parameters
///
/// * `Output` - The success type returned by the command
/// * `Error` - The error type, which must implement [`std::error::Error`]
///
/// # Example
///
/// ```ignore
/// use crate::command::OnceCommand;
/// use std::process::ExitCode;
///
/// struct MyCommand {
/// name: String,
/// }
///
/// impl OnceCommand for MyCommand {
/// type Output = ExitCode;
/// type Error = std::io::Error;
///
/// fn execute(self) -> Result<Self::Output, Self::Error> {
/// println!("Hello, {}!", self.name);
/// Ok(ExitCode::SUCCESS)
/// }
/// }
/// ```