Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
88 additions
and
8 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,5 @@ | ||
# strum | ||
|
||
[crates:strum] の例を書く。 | ||
|
||
[crates:strum]: https://crates.io/crates/strum |
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,27 @@ | ||
// <https://docs.rs/strum_macros/0.24.1/strum_macros/derive.AsRefStr.html> | ||
// impl X for AsRef<str> を追加できる | ||
|
||
#[allow(dead_code)] | ||
#[derive(strum::AsRefStr)] | ||
enum E1 { | ||
A1, | ||
#[strum(serialize = "b")] | ||
B1, | ||
C1(usize), | ||
D1 { | ||
s: String, | ||
}, | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn e1_test() { | ||
assert_eq!(E1::A1.as_ref(), "A1"); | ||
assert_eq!(E1::B1.as_ref(), "b"); | ||
assert_eq!(E1::C1(10).as_ref(), "C1"); | ||
assert_eq!(E1::D1 { s: "s1".to_owned() }.as_ref(), "D1"); | ||
} | ||
} |
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,23 @@ | ||
// <https://docs.rs/strum_macros/0.24.1/strum_macros/derive.EnumCount.html> | ||
// EnumCount は COUNT を追加できる | ||
|
||
#[allow(dead_code)] | ||
#[derive(strum::EnumCount)] | ||
enum E1 { | ||
A1, | ||
B1, | ||
C1, | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
// これがないと E1::COUNT とできない | ||
use strum::EnumCount; | ||
|
||
use super::*; | ||
|
||
#[test] | ||
fn e1_test() { | ||
assert_eq!(E1::COUNT, 3); | ||
} | ||
} |
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