Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/idanarye/rust-smart-default
Rust macro for automatically generating default
https://github.com/idanarye/rust-smart-default
Last synced: 17 days ago
JSON representation
Rust macro for automatically generating default
- Host: GitHub
- URL: https://github.com/idanarye/rust-smart-default
- Owner: idanarye
- License: mit
- Created: 2017-08-16T19:35:02.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2023-12-22T01:41:32.000Z (11 months ago)
- Last Synced: 2024-04-25T15:02:34.526Z (7 months ago)
- Language: Rust
- Size: 51.8 KB
- Stars: 123
- Watchers: 3
- Forks: 7
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
[![Build Status](https://github.com/idanarye/rust-smart-default/workflows/CI/badge.svg)](https://github.com/idanarye/rust-smart-default/actions)
[![Latest Version](https://img.shields.io/crates/v/smart-default.svg)](https://crates.io/crates/smart-default)
[![Rust Documentation](https://img.shields.io/badge/api-rustdoc-blue.svg)](https://idanarye.github.io/rust-smart-default/)# Rust SmartDefault
Custom derive for automatically implementing the `Default` trait with customized default values:
```rust
use smart_default::SmartDefault;#[derive(SmartDefault)]
enum Foo {
Bar,
#[default]
Baz {
#[default = 12]
a: i32,
b: i32,
#[default(Some(Default::default()))]
c: Option,
#[default(_code = "vec![1, 2, 3]")]
d: Vec,
#[default = "four"]
e: String,
},
Qux(i32),
}assert!(Foo::default() == Foo::Baz {
a: 12,
b: 0,
c: Some(0),
d: vec![1, 2, 3],
e: "four".to_owned(),
});
```Requires Rust 1.30+ (for non-string values in attributes), and version 1.56
due to 2021 edition.