Crates.io | try-from-discrim |
lib.rs | try-from-discrim |
version | 1.0.0 |
source | src |
created_at | 2022-09-29 19:26:05.908554 |
updated_at | 2022-09-29 19:26:05.908554 |
description | #[derive(TryFrom / From)] using enum discriminants, with fallback support. |
homepage | |
repository | https://github.com/ISSOtm/try-from-discrim |
max_upload_size | |
id | 676875 |
size | 38,203 |
This library provides convenient derive macros for the standard library's std::convert::TryFrom
and std::convert::From
traits.
[dependencies]
try-from-discrim = "1.0"
and then:
#[macro_use] extern crate try_from_discrim;
#[derive(TryFrom)]
#[from(u8)]
enum RegisterIndex {
B = 0,
C = 1,
D = 2,
E = 3,
H = 4,
L = 5,
HlInd = 6,
A = 7,
}
(You do not need the extern crate
line with Rust 2018 or later.)
The discriminants can be omitted, too! Check the documentation for more information.
impl
s to this crate or vice-versa is not a breaking change.From
using a fallback variant.The generated implementations are compatible with a #[no_std]
environment.
This crate is licensed under the Mozilla Public License 2.0, see the LICENSE file.