Skip to content

Commit 6505de9

Browse files
committed
Fix clippy::new_without_default and remove getter/setter in diff
1 parent a00830a commit 6505de9

File tree

8 files changed

+66
-172
lines changed

8 files changed

+66
-172
lines changed

display/printf.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,17 @@ struct ConvSpec {
3131
zero_pad: bool,
3232
}
3333

34-
impl ConvSpec {
35-
fn new() -> ConvSpec {
36-
ConvSpec {
34+
impl Default for ConvSpec {
35+
fn default() -> Self {
36+
Self {
3737
spec: ' ',
38-
width: None,
39-
precision: None,
40-
left_justify: false,
41-
sign: false,
42-
space: false,
43-
alt_form: false,
44-
zero_pad: false,
38+
width: Default::default(),
39+
precision: Default::default(),
40+
left_justify: Default::default(),
41+
sign: Default::default(),
42+
space: Default::default(),
43+
alt_form: Default::default(),
44+
zero_pad: Default::default(),
4545
}
4646
}
4747
}
@@ -81,7 +81,7 @@ fn escaped_char(c: char) -> char {
8181
fn tokenize_format_str(format: &str) -> Vec<Token> {
8282
let mut tokens: Vec<Token> = Vec::new();
8383
let mut literal = String::with_capacity(format.len());
84-
let mut conversion = ConvSpec::new();
84+
let mut conversion = ConvSpec::default();
8585
let mut width = String::with_capacity(8);
8686
let mut precision = String::with_capacity(8);
8787
let mut state = ParseState::Literal;
@@ -164,7 +164,7 @@ fn tokenize_format_str(format: &str) -> Vec<Token> {
164164
ParseState::Specifier => {
165165
conversion.spec = c;
166166
tokens.push(Token::Conversion(conversion));
167-
conversion = ConvSpec::new();
167+
conversion = ConvSpec::default();
168168
state = ParseState::Literal;
169169
done_with_char = true;
170170
}

file/dd.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -102,20 +102,20 @@ struct Config {
102102
notrunc: bool,
103103
}
104104

105-
impl Config {
106-
fn new() -> Config {
107-
Config {
108-
ifile: String::new(),
109-
ofile: String::new(),
105+
impl Default for Config {
106+
fn default() -> Self {
107+
Self {
108+
ifile: Default::default(),
109+
ofile: Default::default(),
110110
ibs: DEF_BLOCK_SIZE,
111111
obs: DEF_BLOCK_SIZE,
112-
cbs: 0,
113-
seek: 0,
114-
skip: 0,
115-
count: 0,
116-
conversions: Vec::new(),
117-
noerror: false,
118-
notrunc: false,
112+
cbs: Default::default(),
113+
seek: Default::default(),
114+
skip: Default::default(),
115+
count: Default::default(),
116+
conversions: Default::default(),
117+
noerror: Default::default(),
118+
notrunc: Default::default(),
119119
}
120120
}
121121
}
@@ -341,7 +341,7 @@ fn parse_block_size(s: &str) -> Result<usize, Box<dyn std::error::Error>> {
341341
}
342342

343343
fn parse_cmdline(args: &[String]) -> Result<Config, Box<dyn std::error::Error>> {
344-
let mut config = Config::new();
344+
let mut config = Config::default();
345345

346346
for arg in args {
347347
// Split arg into option and argument

file/tee.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,11 @@ struct TeeFile {
3232
f: File,
3333
}
3434

35+
#[derive(Default)]
3536
struct TeeInfo {
3637
outputs: Vec<TeeFile>,
3738
}
3839

39-
impl TeeInfo {
40-
fn new() -> TeeInfo {
41-
TeeInfo {
42-
outputs: Vec::new(),
43-
}
44-
}
45-
}
46-
4740
fn open_outputs(args: &Args, info: &mut TeeInfo) -> io::Result<()> {
4841
for filename in &args.files {
4942
let f_res = OpenOptions::new()
@@ -113,7 +106,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
113106
}
114107
}
115108

116-
let mut state = TeeInfo::new();
109+
let mut state = TeeInfo::default();
117110

118111
open_outputs(&args, &mut state)?;
119112
tee_stdin(&mut state)?;

plib/src/modestr.rs

Lines changed: 14 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -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)]
1616
pub enum ChmodActionOp {
1717
Add,
1818
Remove,
19+
#[default]
1920
Set,
2021
}
2122

22-
#[derive(Debug)]
23+
#[derive(Debug, Default)]
2324
pub 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)]
5942
pub 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)]
8455
pub 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)]
9760
pub enum ChmodMode {
9861
Absolute(u32),
9962
Symbolic(ChmodSymbolic),
10063
}
10164

102-
#[derive(Debug)]
65+
#[derive(Debug, Default)]
10366
enum 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
}

text/asa.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,16 @@ struct AsaState {
3030
lines: Vec<String>,
3131
}
3232

33-
impl AsaState {
34-
fn new() -> AsaState {
35-
AsaState {
33+
impl Default for AsaState {
34+
fn default() -> Self {
35+
Self {
3636
first_line: true,
37-
lines: Vec::new(),
37+
lines: Default::default(),
3838
}
3939
}
40+
}
4041

42+
impl AsaState {
4143
fn push(&mut self, line: &str) {
4244
self.lines.push(line.to_string());
4345
if self.first_line {
@@ -69,7 +71,7 @@ impl AsaState {
6971
fn asa_file(pathname: &PathBuf) -> io::Result<()> {
7072
let mut reader = plib::io::input_reader(pathname, false)?;
7173
let mut line_no: usize = 0;
72-
let mut state = AsaState::new();
74+
let mut state = AsaState::default();
7375

7476
loop {
7577
line_no += 1;

0 commit comments

Comments
 (0)