tryfromfail

Crates.iotryfromfail
lib.rstryfromfail
version0.1.0
sourcesrc
created_at2018-04-20 00:57:27.340102
updated_at2018-04-20 00:57:27.340102
descriptionDerive failing TryFrom for a set of target types.
homepage
repositoryhttps://gitlab.com/samgreen/tryfromfail
max_upload_size
id61495
size5,982
Sam Green (green-s)

documentation

README

tryfromfail

Latest Version Documentation

Custom derive failing TryFrom implementations for a set of target types.

Returns the original value as Err(value).

Example

#[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 {}));
}
Commit count: 3

cargo fmt