cp_library_rs/utils/boolutil.rs
1//! boolから他の値への変換
2
3pub trait BoolUtil {
4 /// `true` → `"Yes"`,`false` → `"No"` に変換
5 fn yesno(&self) -> &'static str;
6 /// `true` → `"\n"`,`false` → `" "` に変換
7 fn endl(&self) -> &'static str;
8}
9
10impl BoolUtil for bool {
11 fn yesno(&self) -> &'static str {
12 if *self {
13 "Yes"
14 } else {
15 "No"
16 }
17 }
18 fn endl(&self) -> &'static str {
19 if *self {
20 "\n"
21 } else {
22 " "
23 }
24 }
25}