Crates.io | constdefault-derive |
lib.rs | constdefault-derive |
version | 0.2.1 |
source | src |
created_at | 2022-09-27 22:54:39.548902 |
updated_at | 2022-09-27 22:57:07.76138 |
description | #[derive(ConstDefault)] |
homepage | |
repository | https://github.com/semtexzv/const-default.rs |
max_upload_size | |
id | 675276 |
size | 7,081 |
A Default
-like trait and derive macros for const
evaluation contexts.
This crate defines the ConstDefault
trait and implements it for
Rust primitives, prelude types, tuples and arrays. Furthermore it
provides a derive macro so that users can implement ConstDefault
easily for their custom types.
no_std
compatibleAdd
[dependencies]
constdefault = { version = "1.0", features = ["derive"] }
to your Cargo.toml
to start using it.
use constdefault::ConstDefault;
fn main() {
assert_eq!(<i32 as ConstDefault>::DEFAULT, 0);
assert_eq!(<Option<i32> as ConstDefault>::DEFAULT, None);
assert_eq!(<String as ConstDefault>::DEFAULT, String::new());
assert_eq!(<Vec<u8> as ConstDefault>::DEFAULT, Vec::new());
}
use constdefault::ConstDefault;
#[derive(ConstDefault, Debug, Default, PartialEq)]
pub struct Color {
r: u8,
g: u8,
b: u8,
}
fn main() {
assert_eq!(
<Color as ConstDefault>::DEFAULT,
Color::default(),
);
}