Skip to content
forked from emk/accessors

(WIP) Getters and setters for Rust using macros 1.1

Notifications You must be signed in to change notification settings

lawliet89/accessors

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

#[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)], 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)]
struct Simple {
    field: String,
}

fn main() {
    let mut s = Simple { field: "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.

About

(WIP) Getters and setters for Rust using macros 1.1

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Rust 100.0%