@@ -12,14 +12,15 @@ use libc::{
1212 S_IWUSR , S_IXGRP , S_IXOTH , S_IXUSR ,
1313} ;
1414
15- #[ derive( PartialEq , Debug ) ]
15+ #[ derive( PartialEq , Debug , Default ) ]
1616pub enum ChmodActionOp {
1717 Add ,
1818 Remove ,
19+ #[ default]
1920 Set ,
2021}
2122
22- #[ derive( Debug ) ]
23+ #[ derive( Debug , Default ) ]
2324pub struct ChmodAction {
2425 pub op : ChmodActionOp ,
2526
@@ -37,25 +38,7 @@ pub struct ChmodAction {
3738 dirty : bool ,
3839}
3940
40- impl ChmodAction {
41- pub fn new ( ) -> ChmodAction {
42- ChmodAction {
43- op : ChmodActionOp :: Set ,
44- copy_user : false ,
45- copy_group : false ,
46- copy_others : false ,
47- read : false ,
48- write : false ,
49- execute : false ,
50- execute_dir : false ,
51- setuid : false ,
52- sticky : false ,
53- dirty : false ,
54- }
55- }
56- }
57-
58- #[ derive( Debug ) ]
41+ #[ derive( Debug , Default ) ]
5942pub struct ChmodClause {
6043 // wholist
6144 pub user : bool ,
@@ -68,39 +51,20 @@ pub struct ChmodClause {
6851 dirty : bool ,
6952}
7053
71- impl ChmodClause {
72- pub fn new ( ) -> ChmodClause {
73- ChmodClause {
74- user : false ,
75- group : false ,
76- others : false ,
77- actions : Vec :: new ( ) ,
78- dirty : false ,
79- }
80- }
81- }
82-
83- #[ derive( Debug ) ]
54+ #[ derive( Debug , Default ) ]
8455pub struct ChmodSymbolic {
8556 pub clauses : Vec < ChmodClause > ,
8657}
8758
88- impl ChmodSymbolic {
89- pub fn new ( ) -> ChmodSymbolic {
90- ChmodSymbolic {
91- clauses : Vec :: new ( ) ,
92- }
93- }
94- }
95-
9659#[ derive( Debug ) ]
9760pub enum ChmodMode {
9861 Absolute ( u32 ) ,
9962 Symbolic ( ChmodSymbolic ) ,
10063}
10164
102- #[ derive( Debug ) ]
65+ #[ derive( Debug , Default ) ]
10366enum ParseState {
67+ #[ default]
10468 Wholist ,
10569 Actionlist ,
10670 ListOrCopy ,
@@ -114,11 +78,11 @@ pub fn parse(mode: &str) -> Result<ChmodMode, String> {
11478 return Ok ( ChmodMode :: Absolute ( m) ) ;
11579 }
11680
117- let mut state = ParseState :: Wholist ;
11881 let mut done_with_char;
119- let mut symbolic = ChmodSymbolic :: new ( ) ;
120- let mut clause = ChmodClause :: new ( ) ;
121- let mut action = ChmodAction :: new ( ) ;
82+ let mut state = ParseState :: default ( ) ;
83+ let mut symbolic = ChmodSymbolic :: default ( ) ;
84+ let mut clause = ChmodClause :: default ( ) ;
85+ let mut action = ChmodAction :: default ( ) ;
12286
12387 for c in mode. chars ( ) {
12488 done_with_char = false ;
@@ -156,7 +120,7 @@ pub fn parse(mode: &str) -> Result<ChmodMode, String> {
156120 action. dirty = false ;
157121 done_with_char = false ;
158122 symbolic. clauses . push ( clause) ;
159- clause = ChmodClause :: new ( ) ;
123+ clause = ChmodClause :: default ( ) ;
160124 state = ParseState :: NextClause ;
161125 }
162126 }
@@ -177,7 +141,7 @@ pub fn parse(mode: &str) -> Result<ChmodMode, String> {
177141 done_with_char = false ;
178142 clause. actions . push ( action) ;
179143 clause. dirty = true ;
180- action = ChmodAction :: new ( ) ;
144+ action = ChmodAction :: default ( ) ;
181145 state = ParseState :: Actionlist ;
182146 }
183147 }
@@ -196,7 +160,7 @@ pub fn parse(mode: &str) -> Result<ChmodMode, String> {
196160 done_with_char = false ;
197161 clause. actions . push ( action) ;
198162 clause. dirty = true ;
199- action = ChmodAction :: new ( ) ;
163+ action = ChmodAction :: default ( ) ;
200164 state = ParseState :: Actionlist ;
201165 }
202166 }
0 commit comments