Crates.io | orx-pseudo-default-derive |
lib.rs | orx-pseudo-default-derive |
version | 1.0.0 |
source | src |
created_at | 2024-08-13 15:06:21.73046 |
updated_at | 2024-08-13 15:06:21.73046 |
description | Derives the PseudoDefault trait that allows to create a cheap default instance of a type, which does not claim to be useful. |
homepage | |
repository | https://github.com/orxfun/orx-pseudo-default-derive/ |
max_upload_size | |
id | 1336154 |
size | 10,836 |
Derives the PseudoDefault
trait that allows to create a cheap default instance of a type, which does not claim to be useful.
use orx_pseudo_default::PseudoDefault;
use orx_pseudo_default_derive::PseudoDefault;
#[derive(PseudoDefault)]
struct ChildStruct {
a: String,
b: char,
c: Vec<u32>,
}
#[derive(PseudoDefault)]
struct MyStruct {
x: ChildStruct,
y: bool,
z: Option<usize>,
}
assert_eq!(String::pseudo_default(), MyStruct::pseudo_default().x.a);
assert_eq!(char::pseudo_default(), MyStruct::pseudo_default().x.b);
assert_eq!(Vec::<u32>::pseudo_default(), MyStruct::pseudo_default().x.c);
assert_eq!(bool::pseudo_default(), MyStruct::pseudo_default().y);
assert_eq!(
Option::<usize>::pseudo_default(),
MyStruct::pseudo_default().z
);