Crates.io | tryfromfail |
lib.rs | tryfromfail |
version | 0.1.0 |
source | src |
created_at | 2018-04-20 00:57:27.340102 |
updated_at | 2018-04-20 00:57:27.340102 |
description | Derive failing TryFrom for a set of target types. |
homepage | |
repository | https://gitlab.com/samgreen/tryfromfail |
max_upload_size | |
id | 61495 |
size | 5,982 |
tryfromfail
Custom derive failing TryFrom
implementations for a set of target types.
Returns the original value as Err(value)
.
#[macro_use]
extern crate tryfromfail;
use std::convert::TryInto;
#[derive(Debug, PartialEq, FailingTryFrom)]
#[FailingTryFrom(OtherType)]
struct SomeType {}
#[derive(Debug, PartialEq)]
struct OtherType {}
#[test]
fn works() {
let val = OtherType {};
let failed_try_from: Result<SomeType, OtherType> = val.try_into();
assert_eq!(failed_try_from, Err(OtherType {}));
}