Skip to content

qtlis/getset

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

getset

Build Status Build status

Getset, we're ready to go!

A procedural macro for generating the most basic getters and setters on fields.

Getters are generated as fn field(&self) -> &type, while setters are generated as fn field(&mut self, val: type).

These macros are not intended to be used on fields which require custom logic inside of their setters and getters. Just write your own in that case!

Yes! It supports nightly with pub(crate) etc!

#[macro_use]
extern crate getset;

#[derive(Getters, Setters, MutGetters, Default)]
pub struct Foo<T> where T: Copy + Clone + Default {
    /// Doc comments are supported!
    /// Multiline, even.
    #[get] #[set] #[get_mut]
    private: T,

    /// Doc comments are supported!
    /// Multiline, even.
    #[get = "pub"] #[set = "pub"] #[get_mut = "pub"]
    public: T,
}

fn main() {
    let mut foo = Foo::default();
    foo.set_private(1);
    (*foo.private_mut()) += 1;
    assert_eq!(*foo.private(), 2);
}

About

Getters and Setters for Rust.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Rust 100.0%