Crates.io | cell_derive |
lib.rs | cell_derive |
version | 0.1.0 |
source | src |
created_at | 2023-05-22 08:04:28.508979 |
updated_at | 2023-05-22 08:04:28.508979 |
description | A derive macro for quickly implementing `get_or_init` and `get_mut` functions for structs that contain `OnceCell` or `OnceLock` structs. |
homepage | https://github.com/pintariching/cell_derive |
repository | https://github.com/pintariching/cell_derive |
max_upload_size | |
id | 870437 |
size | 5,665 |
A derive macro for quickly implementing get_or_init
and get_mut
functions for structs that contain OnceCell
or OnceLock
structs.
To use the macro on a struct, you need to define an initialization function somewhere and specify it with the init
attribute.
For example:
#[derive(GetDerive)]
struct ToBeDerived {
#[init(init_val)]
val: OnceCell<String>,
}
fn init_val() -> String {
"Some value".to_string()
}
You can get the value of the field by calling the val()
function that is generated.
get_mut
.OnceLock
.