accessors

Crates.ioaccessors
lib.rsaccessors
version0.0.3
sourcesrc
created_at2016-10-12 03:02:52.542649
updated_at2016-10-12 20:56:06.764185
description(WIP) Getters and setters for Rust using macros 1.1
homepage
repositoryhttps://github.com/emk/accessors
max_upload_size
id6816
size6,757
Eric Kidd (emk)

documentation

README

#[derive(accessors)]: getters and setters for Rust (WIP)

This is a work in progress! The API is subject to change.

We use the new macros 1.1 support in nightly Rust to automatically generate basic getters and setters. This is useful if you have a library that exports a struct with lots of fields, but you don't want to make the fields themselves public.

If you specify #[setters(into = true)], you can generate setters which use Into to automatically convert to the desired type.

#![feature(proc_macro)]

#[macro_use]
extern crate accessors;

#[derive(getters, setters)]
#[setters(into = true)]
struct Simple {
    field: String,
}

impl Simple {
    pub fn new(field: String) -> Simple {
        Simple { field: field }
    }
}

fn main() {
    let mut s = Simple::new("hello".to_owned());
    println!("{}", s.field());
    s.set_field("there");
}

Right now, you can only use this with nightly Rust, but David Tolnay has laid out a roadmap for how to get it working with stable Rust.

Commit count: 12

cargo fmt