small_read_only 0.1.0

A macro to implement getters on a struct
Documentation
  • Coverage
  • 100%
    2 out of 2 items documented1 out of 2 items with examples
  • Size
  • Source code size: 5.27 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 280.81 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 4s Average build duration of successful builds.
  • all releases: 4s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Ike-l/read_only
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • Ike-l

small_read_only

This crate adds #[derive(ReadOnly)]. It implements getters for all fields without the #[NoRead] attribute.

It works for:

  • Structs

Example

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");

License

MIT or Apache-2.0