#![no_std] #![deny(missing_docs)] #![doc = include_str!("../README.md")] /// See rewrap() pub trait Rewrap { /// Converts `Result, Error>` into `Result`, where `Error` implements `Into`. /// See more examples in tests. /// ``` ///# use std::any::{Any, type_name as std_type_name, TypeId}; /// use rewrap::Rewrap; ///# use thiserror::Error; ///# #[derive(Error, Debug)] ///# enum OriginalError {} ///# #[derive(Error, Debug)] ///# enum TargetError { ///# #[error(transparent)] ///# Original(#[from] OriginalError) ///# } /// let result: Result<(), TargetError> = Ok(()); /// let result_of_result: Result, OriginalError> = Ok(result); /// let rewrapped_result: Result<(), TargetError> = result_of_result.rewrap(); /// let unwrapped_result: () = rewrapped_result.unwrap(); /// ``` #[allow(clippy::missing_errors_doc)] fn rewrap(self) -> Result; } impl Rewrap for Result, Error> where Error: Into, { #[allow(clippy::inline_always)] #[inline(always)] fn rewrap(self) -> Result { self.unwrap_or_else(|why| Err(why.into())) } }