accessorise 0.2.0

Add accessors to your struct and trait implementations.
Documentation
  • Coverage
  • 4.55%
    1 out of 22 items documented1 out of 22 items with examples
  • Size
  • Source code size: 33.17 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 409.05 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 9s Average build duration of successful builds.
  • all releases: 11s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • coruscateor/accessorise
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • coruscateor

Accessorise

Crates.io License Downloads Docs Twitch Status

X | Twitch | Youtube | Mastodon | GitHub | GitHub Sponsors

Add accessors to your struct and trait implementations.


use accessorise::*;

//use super::*;

use paste::paste;

trait TestTrait
{

    trait_get_val!(a_number, i32);

    trait_set_val!(a_number, i32);

    trait_get_ref!(a_string, String);

    trait_get_mut!(a_string, String);

    trait_get_val!(a_number_doc, i8, "This is a getter declaration, presumably for a number field.");

    trait_set_val!(a_number_doc, i8, "This is a setter declaration, presumably for a number field.");

    trait_get_ref!(a_string_doc, String, "This is a getter declaration, presumably for a String field.");

    trait_get_mut!(a_string_doc, String, "This is a setter declaration, presumably for a String field.");

}

#[derive(Default)]
struct TestStruct
{

    a_number: i32,
    a_string: String,
    a_number_doc: i8,
    a_string_doc: String,
    some_numbers: Vec<i32>

}

impl TestStruct
{

    pub fn new() -> Self
    {

        Self::default()

    }

    impl_get_val!(a_number, i32);

    impl_set_val!(a_number, i32);

    impl_get_val!(a_string, String);

    impl_get_val!(a_string_doc, String, "Returns a cloned String.");

    impl_get_ref!(some_numbers, Vec<i32>, "Returns some numbers by reference.");

    impl_get_mut!(some_numbers, Vec<i32>, "Returns some numbers by mutable reference.");

    impl_get_val!(some_numbers, Vec<i32>);

    impl_set_val!(some_numbers, Vec<i32>);

}

impl TestTrait for TestStruct
{

    impl_trait_get_val!(a_number, i32);

    impl_trait_set_val!(a_number, i32);

    impl_trait_get_ref!(a_string, String);

    impl_trait_get_mut!(a_string, String);

    impl_trait_get_val!(a_number_doc, i8, "This is a getter implementation for a number field.");

    impl_trait_set_val!(a_number_doc, i8, "This is a setter implementation for a number field.");

    impl_trait_get_ref!(a_string_doc, String, "This is a getter implementation for a String field.");

    impl_trait_get_mut!(a_string_doc, String, "This is a setter implementation for a String field.");
    
}

fn main()
{
    
    let mut test_struct = TestStruct::new();

    let _number = test_struct.a_number();

    test_struct.set_a_number(5);

}

Compiler:

Build with the latest stable compiler.

Todo:

  • Add more documentation
  • Add more macros
  • Add rules for things like aliases and multiple accessor declarations and definitions to the macros that are already part of this crate.

Coding Style

This project uses a coding style the emphasises the use of white space over keeping the line and column counts as low as possible.

So this:

fn bar() {}

fn foo()
{

    bar();

}

Not this:

fn bar() {}

fn foo()
{
    bar();
}

License

Licensed under either of:

at your discretion

Contributing

Please clone the repository and create an issue explaining what feature or features you'd like to add or bug or bugs you'd like to fix and perhaps how you intend to implement these additions or fixes. Try to include details though it doesn't need to be exhaustive and we'll take it from there (dependant on availability).

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.