-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #76 from pnevyk/skip-attribute
Add option for skipping fields
- Loading branch information
Showing
4 changed files
with
153 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#[macro_use] | ||
extern crate getset; | ||
|
||
#[derive(CopyGetters, Setters)] | ||
#[getset(get_copy, set)] | ||
pub struct Plain { | ||
// If the field was not skipped, the compiler would complain about moving a | ||
// non-copyable type. | ||
#[getset(skip)] | ||
non_copyable: String, | ||
|
||
copyable: usize, | ||
// Invalid use of skip -- compilation error. | ||
// #[getset(skip, get_copy)] | ||
// non_copyable2: String, | ||
|
||
// Invalid use of skip -- compilation error. | ||
// #[getset(get_copy, skip)] | ||
// non_copyable2: String, | ||
} | ||
|
||
impl Plain { | ||
fn custom_non_copyable(&self) -> &str { | ||
&self.non_copyable | ||
} | ||
|
||
// If the field was not skipped, the compiler would complain about duplicate | ||
// definitions of `set_non_copyable`. | ||
fn set_non_copyable(&mut self, val: String) -> &mut Self { | ||
self.non_copyable = val; | ||
self | ||
} | ||
} | ||
|
||
impl Default for Plain { | ||
fn default() -> Self { | ||
Plain { | ||
non_copyable: "foo".to_string(), | ||
copyable: 3, | ||
} | ||
} | ||
} | ||
|
||
#[test] | ||
fn test_plain() { | ||
let mut val = Plain::default(); | ||
val.copyable(); | ||
val.custom_non_copyable(); | ||
val.set_non_copyable("bar".to_string()); | ||
} |