Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 12 additions & 19 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,10 @@ where
public: T,
}

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

You can use `cargo-expand` to generate the output. Here are the functions that the above generates (Replicate with `cargo expand --example simple`):
Expand Down Expand Up @@ -105,10 +103,8 @@ Attributes can be set on struct level for all fields in struct as well. Field le
precedence.

```rust
#[macro_use]
extern crate getset;

mod submodule {
use getset::{Getters, MutGetters, CopyGetters, Setters};
#[derive(Getters, CopyGetters, Default)]
#[get_copy = "pub"] // By default add a pub getting for all fields.
pub struct Foo {
Expand All @@ -121,29 +117,26 @@ mod submodule {
foo.private();
}
}
fn main() {
let mut foo = submodule::Foo::default();
foo.public();
}

let mut foo = submodule::Foo::default();
foo.public();
```

For some purposes, it's useful to have the `get_` prefix on the getters for
either legacy of compatability reasons. It is done with `with_prefix`.

```rust
#[macro_use]
extern crate getset;
use getset::{Getters, MutGetters, CopyGetters, Setters};

#[derive(Getters, Default)]
pub struct Foo {
#[get = "pub with_prefix"]
field: bool,
}

fn main() {
let mut foo = Foo::default();
let val = foo.get_field();
}

let mut foo = Foo::default();
let val = foo.get_field();
```
*/

Expand Down