Crates.io | sensible |
lib.rs | sensible |
version | 0.1.0 |
source | src |
created_at | 2022-05-21 02:05:58.580836 |
updated_at | 2022-05-21 02:05:58.580836 |
description | Configurable derive macro for implementing Default |
homepage | |
repository | https://github.com/lukesneeringer/sensible |
max_upload_size | |
id | 590544 |
size | 9,646 |
This is a crate for a more configurable derive macro to derive an
implementation for Default
. Rust's std::default
module provides a
derive implementation, but for structs, it requires that:
Default
.Default
implementation.This is fine for many cases, but consider the case of a large struct where just
one or two fields should default to something other than their type's Default
implementation: now you have to implement the whole thing.
sensible
provides a configurable derive macro that allows giving certain
fields alternate default values.
use sensible::Default;
#[derive(Default)]
struct Foo {
a: u32, // default value: 0
#[default(42)]
b: u32, // default value: 42
}