Crates.io | if_empty_derive |
lib.rs | if_empty_derive |
version | 0.1.0 |
source | src |
created_at | 2021-07-30 22:38:16.686604 |
updated_at | 2021-07-30 22:38:16.686604 |
description | Proc macro to generate if_empty for types that have is_empty implemented |
homepage | https://github.com/cschlosser/IfEmpty/tree/master/derive_macro |
repository | https://github.com/cschlosser/IfEmpty |
max_upload_size | |
id | 429439 |
size | 20,826 |
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'
}