Crates.io | rewrap |
lib.rs | rewrap |
version | 1.0.1 |
source | src |
created_at | 2022-07-30 15:01:36.427055 |
updated_at | 2022-07-30 15:12:30.06224 |
description | `Result |
homepage | |
repository | https://gitlab.com/liqu1dator_mukh/rewrap |
max_upload_size | |
id | 635573 |
size | 3,691 |
Ever wanted to convert Result<Result<T, E>, F>
into Result<T, F>
? No? Anyway...
cargo add rewrap
use rewrap::Rewrap;
use thiserror::Error;
#[derive(Error, Debug)]
enum OriginalError {}
#[derive(Error, Debug)]
enum TargetError {
#[error(transparent)]
Original(#[from] OriginalError)
}
fn main() {
let result: Result<(), TargetError> = Ok(());
let result_of_result: Result<Result<(), TargetError>, OriginalError> = Ok(result);
let rewrapped_result: Result<(), TargetError> = result_of_result.rewrap();
let unwrapped_result: () = rewrapped_result.unwrap();
}