4
4
strum:: { EnumCount , EnumIter , EnumString , IntoStaticStr } ,
5
5
} ;
6
6
7
- #[ derive( Default ) ]
8
- pub struct InfoFieldOn {
9
- pub git_info : bool ,
10
- pub project : bool ,
11
- pub head : bool ,
12
- pub version : bool ,
13
- pub created : bool ,
14
- pub dependencies : bool ,
15
- pub languages : bool ,
16
- pub authors : bool ,
17
- pub last_change : bool ,
18
- pub repo : bool ,
19
- pub commits : bool ,
20
- pub pending : bool ,
21
- pub lines_of_code : bool ,
22
- pub size : bool ,
23
- pub license : bool ,
24
- }
25
-
26
7
#[ derive( PartialEq , Eq , EnumString , EnumCount , EnumIter , IntoStaticStr ) ]
27
8
#[ strum( serialize_all = "snake_case" ) ]
28
- pub enum InfoFields {
9
+ pub enum InfoField {
29
10
GitInfo ,
30
11
Project ,
31
12
HEAD ,
@@ -44,32 +25,52 @@ pub enum InfoFields {
44
25
UnrecognizedField ,
45
26
}
46
27
47
- pub fn get_disabled_fields ( fields_to_hide : Vec < String > ) -> Result < InfoFieldOn > {
48
- let mut disabled_fields = InfoFieldOn { ..Default :: default ( ) } ;
28
+ #[ derive( Default ) ]
29
+ pub struct InfoFieldOff {
30
+ pub git_info : bool ,
31
+ pub project : bool ,
32
+ pub head : bool ,
33
+ pub version : bool ,
34
+ pub created : bool ,
35
+ pub dependencies : bool ,
36
+ pub languages : bool ,
37
+ pub authors : bool ,
38
+ pub last_change : bool ,
39
+ pub repo : bool ,
40
+ pub commits : bool ,
41
+ pub pending : bool ,
42
+ pub lines_of_code : bool ,
43
+ pub size : bool ,
44
+ pub license : bool ,
45
+ }
46
+
47
+ impl InfoFieldOff {
48
+ pub fn new ( fields_to_hide : Vec < String > ) -> Result < Self > {
49
+ let mut disabled_fields = InfoFieldOff { ..Default :: default ( ) } ;
49
50
50
- for field in fields_to_hide. iter ( ) {
51
- let item = InfoFields :: from_str ( field. to_lowercase ( ) . as_str ( ) )
52
- . unwrap_or ( InfoFields :: UnrecognizedField ) ;
51
+ for field in fields_to_hide. iter ( ) {
52
+ let item = InfoField :: from_str ( field. to_lowercase ( ) . as_str ( ) ) ?;
53
53
54
- match item {
55
- InfoFields :: GitInfo => disabled_fields. git_info = true ,
56
- InfoFields :: Project => disabled_fields. project = true ,
57
- InfoFields :: HEAD => disabled_fields. head = true ,
58
- InfoFields :: Version => disabled_fields. version = true ,
59
- InfoFields :: Created => disabled_fields. created = true ,
60
- InfoFields :: Dependencies => disabled_fields. dependencies = true ,
61
- InfoFields :: Languages => disabled_fields. languages = true ,
62
- InfoFields :: Authors => disabled_fields. authors = true ,
63
- InfoFields :: LastChange => disabled_fields. last_change = true ,
64
- InfoFields :: Repo => disabled_fields. repo = true ,
65
- InfoFields :: Pending => disabled_fields. pending = true ,
66
- InfoFields :: Commits => disabled_fields. commits = true ,
67
- InfoFields :: LinesOfCode => disabled_fields. lines_of_code = true ,
68
- InfoFields :: Size => disabled_fields. size = true ,
69
- InfoFields :: License => disabled_fields. license = true ,
70
- _ => ( ) ,
54
+ match item {
55
+ InfoField :: GitInfo => disabled_fields. git_info = true ,
56
+ InfoField :: Project => disabled_fields. project = true ,
57
+ InfoField :: HEAD => disabled_fields. head = true ,
58
+ InfoField :: Version => disabled_fields. version = true ,
59
+ InfoField :: Created => disabled_fields. created = true ,
60
+ InfoField :: Dependencies => disabled_fields. dependencies = true ,
61
+ InfoField :: Languages => disabled_fields. languages = true ,
62
+ InfoField :: Authors => disabled_fields. authors = true ,
63
+ InfoField :: LastChange => disabled_fields. last_change = true ,
64
+ InfoField :: Repo => disabled_fields. repo = true ,
65
+ InfoField :: Pending => disabled_fields. pending = true ,
66
+ InfoField :: Commits => disabled_fields. commits = true ,
67
+ InfoField :: LinesOfCode => disabled_fields. lines_of_code = true ,
68
+ InfoField :: Size => disabled_fields. size = true ,
69
+ InfoField :: License => disabled_fields. license = true ,
70
+ _ => ( ) ,
71
+ }
71
72
}
72
- }
73
73
74
- Ok ( disabled_fields)
74
+ Ok ( disabled_fields)
75
+ }
75
76
}
0 commit comments