trait

Termination: custom return type for main

Termination lets main return a type that reports the process exit code. This example defines a small successful application outcome; ordinary CLI programs can usually return Result or ExitCode without defining a new type. The report method is called by Rust at the program boundary. Fixture: Expected stdout (not executed): report complete Expected stderr: (empty) Expected exit: 0 Common mistake: Implementing Termination for internal business functions when a simple Result is clearer.

Formal Syntax & Structure

rust syntaxrust
impl std::process::Termination for AppOutcome

Working Example

Example Snippetrust
struct AppOutcome(std::process::ExitCode);impl std::process::Termination for AppOutcome {    fn report(self) -> std::process::ExitCode { self.0 }}fn main() -> AppOutcome {    use std::process::ExitCode;    println!("report complete");    AppOutcome(ExitCode::SUCCESS)}
Rust Reference