better-default-derive

Crates.iobetter-default-derive
lib.rsbetter-default-derive
version0.1.1
sourcesrc
created_at2023-04-07 10:05:01.787528
updated_at2023-04-08 09:32:18.176388
descriptionA better Default macro
homepage
repositoryhttps://github.com/monadplus/better-default-derive
max_upload_size
id832859
size15,276
Arnau Abella (monadplus)

documentation

README

better-default-derive crates.io github actions badge

A better std::default::Default macro.

Supports:

  • Struct
    • Unit
    • Named
    • Unnamed
    • Generic
  • Enum
    • Unit
    • Named
    • Unnamed
    • Generic

Usage

[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()));
}

Roadmap

  • 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>,
    }
    
Commit count: 3

cargo fmt