Skip to main content

into_result/
lib.rs

1#![cfg_attr(not(feature = "std"), no_std)]
2
3#[cfg(all(feature = "command", not(feature = "std")))]
4compile_error!("`command` feature requires `std`");
5
6#[cfg(all(feature = "command", feature = "std"))]
7pub mod command;
8
9use core::{option::Option, result::Result};
10
11pub trait IntoResult<T, E> {
12    fn into_result(self) -> Result<T, E>;
13
14    fn into_option(self) -> Option<T>
15    where
16        Self: Sized,
17    {
18        self.into_result().ok()
19    }
20}
21
22impl IntoResult<(), ()> for bool {
23    fn into_result(self) -> Result<(), ()> {
24        if self {
25            Ok(())
26        } else {
27            Err(())
28        }
29    }
30}