Skip to main content

sel4_root_task/
termination.rs

1//
2// Copyright 2023, Colias Group, LLC
3//
4// SPDX-License-Identifier: BSD-2-Clause
5//
6
7use core::fmt;
8
9pub use sel4_never_polyfill::Never;
10
11/// Trait for the return type of [`#[root_task]`](crate::root_task) main functions.
12pub trait Termination {
13    type Error: fmt::Debug;
14
15    fn report(self) -> Self::Error;
16}
17
18impl Termination for Never {
19    type Error = Never;
20
21    fn report(self) -> Self::Error {
22        self
23    }
24}
25
26impl<E: fmt::Debug> Termination for Result<Never, E> {
27    type Error = E;
28
29    fn report(self) -> Self::Error {
30        match self {
31            #[allow(unreachable_patterns)]
32            Ok(absurdity) => match absurdity {},
33            Err(err) => err,
34        }
35    }
36}