orx-pseudo-default-derive

Crates.ioorx-pseudo-default-derive
lib.rsorx-pseudo-default-derive
version1.0.0
sourcesrc
created_at2024-08-13 15:06:21.73046
updated_at2024-08-13 15:06:21.73046
descriptionDerives the PseudoDefault trait that allows to create a cheap default instance of a type, which does not claim to be useful.
homepage
repositoryhttps://github.com/orxfun/orx-pseudo-default-derive/
max_upload_size
id1336154
size10,836
Ugur Arikan (orxfun)

documentation

README

orx-pseudo-default-derive

orx-pseudo-default-derive crate orx-pseudo-default-derive documentation

Derives the PseudoDefault trait that allows to create a cheap default instance of a type, which does not claim to be useful.

Example

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
);
Commit count: 0

cargo fmt