if_empty_derive

Crates.ioif_empty_derive
lib.rsif_empty_derive
version0.1.0
sourcesrc
created_at2021-07-30 22:38:16.686604
updated_at2021-07-30 22:38:16.686604
descriptionProc macro to generate if_empty for types that have is_empty implemented
homepagehttps://github.com/cschlosser/IfEmpty/tree/master/derive_macro
repositoryhttps://github.com/cschlosser/IfEmpty
max_upload_size
id429439
size20,826
Christoph Schlosser (cschlosser)

documentation

README

IfEmpty derive macro

This crate provides a derive macro implementing the if_empty functionality if the type has an is_empty function.

#[derive(IfEmpty)]
struct Example {
    value: String,
}

impl Example {
    fn is_empty(&self) -> bool {
        self.value.is_empty()
    }
}

fn main() {
    let example = Example {
        value: String::new(),
    };
    print!("Example '{}'", example.value);
    // Example ''

    let not_empty_example = e.if_empty(Example {
        value: "default val".to_string(),
    });

    print!("Example '{}'", not_empty_example.value);
    // Example 'default val'
}
Commit count: 48

cargo fmt