Crates.io | better-default-derive |
lib.rs | better-default-derive |
version | 0.1.1 |
source | src |
created_at | 2023-04-07 10:05:01.787528 |
updated_at | 2023-04-08 09:32:18.176388 |
description | A better Default macro |
homepage | |
repository | https://github.com/monadplus/better-default-derive |
max_upload_size | |
id | 832859 |
size | 15,276 |
A better std::default::Default macro.
Supports:
[dependencies]
better-default-derive = "0.1.0"
use better_default_derive::Default;
#[derive(Debug, PartialEq, Eq, Default)]
enum Either<L, R> {
Left(L),
#[default]
Right(R),
}
fn main() {
let either: Either<String, u8> = Either::default();
assert_eq!(either, Either::Right(u8::default()));
}
Better error message when a field is missing the Default
instance.
Support union types
Support associated types
use better_default_derive::Default;
pub trait Trait {
type Value;
}
#[derive(Default)]
pub struct Field<T: Trait> {
values: Vec<T::Value>,
}