-
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.
Add fluent setters, that can be used for chaining setters, like in mo…
…dern Rust
- Loading branch information
Showing
4 changed files
with
171 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
#[macro_use] | ||
extern crate getset; | ||
|
||
use crate::submodule::other::{Generic, Plain, Where}; | ||
|
||
// For testing `pub(super)` | ||
mod submodule { | ||
// For testing `pub(in super::other)` | ||
pub mod other { | ||
#[derive(FluentSetters, Default)] | ||
#[set_fluent] | ||
pub struct Plain { | ||
/// A doc comment. | ||
/// Multiple lines, even. | ||
private_accessible: usize, | ||
|
||
/// A doc comment. | ||
#[set_fluent = "pub"] | ||
public_accessible: usize, | ||
|
||
/// This field is used for testing chaining. | ||
#[set_fluent = "pub"] | ||
second_public_accessible: bool, | ||
// /// A doc comment. | ||
// #[set_fluent = "pub(crate)"] | ||
// crate_accessible: usize, | ||
|
||
// /// A doc comment. | ||
// #[set_fluent = "pub(super)"] | ||
// super_accessible: usize, | ||
|
||
// /// A doc comment. | ||
// #[set_fluent = "pub(in super::other)"] | ||
// scope_accessible: usize, | ||
} | ||
|
||
#[derive(FluentSetters, Default)] | ||
#[set_fluent] | ||
pub struct Generic<T: Copy + Clone + Default> { | ||
/// A doc comment. | ||
/// Multiple lines, even. | ||
private_accessible: T, | ||
|
||
/// A doc comment. | ||
#[set_fluent = "pub"] | ||
public_accessible: T, | ||
// /// A doc comment. | ||
// #[set_fluent = "pub(crate)"] | ||
// crate_accessible: usize, | ||
|
||
// /// A doc comment. | ||
// #[set_fluent = "pub(super)"] | ||
// super_accessible: usize, | ||
|
||
// /// A doc comment. | ||
// #[set_fluent = "pub(in super::other)"] | ||
// scope_accessible: usize, | ||
} | ||
|
||
#[derive(FluentSetters, Default)] | ||
#[set_fluent] | ||
pub struct Where<T> | ||
where | ||
T: Copy + Clone + Default, | ||
{ | ||
/// A doc comment. | ||
/// Multiple lines, even. | ||
private_accessible: T, | ||
|
||
/// A doc comment. | ||
#[set_fluent = "pub"] | ||
public_accessible: T, | ||
// /// A doc comment. | ||
// #[set_fluent = "pub(crate)"] | ||
// crate_accessible: usize, | ||
|
||
// /// A doc comment. | ||
// #[set_fluent = "pub(super)"] | ||
// super_accessible: usize, | ||
|
||
// /// A doc comment. | ||
// #[set_fluent = "pub(in super::other)"] | ||
// scope_accessible: usize, | ||
} | ||
|
||
#[test] | ||
fn test_plain() { | ||
let mut val = Plain::default(); | ||
val.set_private_accessible(1); | ||
} | ||
|
||
#[test] | ||
fn test_generic() { | ||
let mut val = Generic::default(); | ||
val.set_private_accessible(1); | ||
} | ||
|
||
#[test] | ||
fn test_where() { | ||
let mut val = Where::default(); | ||
val.set_private_accessible(1); | ||
} | ||
} | ||
} | ||
|
||
#[test] | ||
fn test_plain() { | ||
let mut val = Plain::default(); | ||
val.set_public_accessible(1); | ||
} | ||
|
||
#[test] | ||
fn test_generic() { | ||
let mut val = Generic::default(); | ||
val.set_public_accessible(1); | ||
} | ||
|
||
#[test] | ||
fn test_where() { | ||
let mut val = Where::default(); | ||
val.set_public_accessible(1); | ||
} | ||
|
||
#[test] | ||
fn test_chaining() { | ||
let mut val = Plain::default(); | ||
val.set_public_accessible(1) | ||
.set_second_public_accessible(true); | ||
} |
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