Crates.io | boring-derive |
lib.rs | boring-derive |
version | 0.1.1 |
source | src |
created_at | 2024-07-02 21:53:47.091303 |
updated_at | 2024-07-04 04:45:07.69957 |
description | Derive macros for some common patterns |
homepage | |
repository | https://github.com/BenPski/boring-derive |
max_upload_size | |
id | 1289969 |
size | 36,359 |
Derive macros for simple implementations of traits.
For example From
usually has very trivial implementations.
enum Thing {
Item1(String),
Item2(usize),
Item3(f32),
}
impl From<String> for Thing {
fn from(value: String) -> Self {
Thing::Item1(value)
}
}
impl From<usize> for Thing {
fn from(value: usize) -> Self {
Thing::Item2(value)
}
}
impl From<f32> for Thing {
fn from(value: f32) -> Self {
Thing::Item3(value)
}
}
So instead just:
#[derive(From)]
enum Thing {
Item1(String),
Item2(usize),
Item3(f32),
}