use core::fmt::Debug;
pub trait Termination {
fn terminate(self);
}
impl Termination for () {
fn terminate(self) {}
}
impl<T, E> Termination for Result<T, E>
where
T: Termination,
E: Debug,
{
fn terminate(self) {
match self {
Ok(value) => value.terminate(),
Err(error) => panic!("{error:?}"),
}
}
}
#[cfg(test)]
mod tests {
use super::Termination;
use gba_test::test;
#[test]
fn terminate_unit() {
().terminate();
}
#[test]
fn terminate_ok() {
Ok::<_, ()>(()).terminate()
}
#[test]
#[should_panic]
fn terminate_err() {
Err::<(), _>("foo").terminate()
}
}