use std::marker::PhantomData;
use mingling_core::{ProgramCollect, hook::ProgramHook, setup::ProgramSetup, this};
use crate::res::ExitCode;
pub struct ExitCodeSetup<C> {
_collect: PhantomData<C>,
}
impl<C> Default for ExitCodeSetup<C>
where
C: ProgramCollect<Enum = C> + 'static,
{
fn default() -> Self {
Self {
_collect: Default::default(),
}
}
}
impl<C> ProgramSetup<C> for ExitCodeSetup<C>
where
C: ProgramCollect<Enum = C> + 'static,
{
fn setup(&mut self, program: &mut crate::Program<C>) {
program.with_resource(ExitCode { exit_code: 0 });
program.with_hook(ProgramHook::empty().on_finish(|| {
let this = this::<C>().res_or_default::<ExitCode>();
this.exit_code
}));
}
}