Crates.io | small_read_only |
lib.rs | small_read_only |
version | 0.1.0 |
source | src |
created_at | 2024-08-29 17:33:32.835983 |
updated_at | 2024-08-29 17:33:32.835983 |
description | A macro to implement getters on a struct |
homepage | |
repository | https://github.com/Ike-l/small_read_only |
max_upload_size | |
id | 1356485 |
size | 4,632 |
This crate adds #[derive(ReadOnly)]
.
It implements getters for all fields without the #[NoRead]
attribute.
It works for:
use small_read_only::ReadOnly;
#[derive(ReadOnly)]
pub struct A<'a> {
b: usize,
c: String,
d: &'a str,
}
impl<'a> A<'a> {
pub fn new(b: usize, c: String, d: &'a str) -> Self {
Self {
b, c, d
}
}
}
let a = A::new(1, "c".to_string(), "d");
assert_eq!(a.b(), &1);
assert_eq!(a.c(), "c");
assert_eq!(a.d(), &"d");
MIT or Apache-2.0