Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions display/printf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ struct ConvSpec {
zero_pad: bool,
}

impl ConvSpec {
fn new() -> ConvSpec {
ConvSpec {
impl Default for ConvSpec {
fn default() -> Self {
Self {
spec: ' ',
width: None,
precision: None,
left_justify: false,
sign: false,
space: false,
alt_form: false,
zero_pad: false,
width: Default::default(),
precision: Default::default(),
left_justify: Default::default(),
sign: Default::default(),
space: Default::default(),
alt_form: Default::default(),
zero_pad: Default::default(),
}
}
}
Expand Down Expand Up @@ -81,7 +81,7 @@ fn escaped_char(c: char) -> char {
fn tokenize_format_str(format: &str) -> Vec<Token> {
let mut tokens: Vec<Token> = Vec::new();
let mut literal = String::with_capacity(format.len());
let mut conversion = ConvSpec::new();
let mut conversion = ConvSpec::default();
let mut width = String::with_capacity(8);
let mut precision = String::with_capacity(8);
let mut state = ParseState::Literal;
Expand Down Expand Up @@ -164,7 +164,7 @@ fn tokenize_format_str(format: &str) -> Vec<Token> {
ParseState::Specifier => {
conversion.spec = c;
tokens.push(Token::Conversion(conversion));
conversion = ConvSpec::new();
conversion = ConvSpec::default();
state = ParseState::Literal;
done_with_char = true;
}
Expand Down
26 changes: 13 additions & 13 deletions file/dd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,20 +102,20 @@ struct Config {
notrunc: bool,
}

impl Config {
fn new() -> Config {
Config {
ifile: String::new(),
ofile: String::new(),
impl Default for Config {
fn default() -> Self {
Self {
ifile: Default::default(),
ofile: Default::default(),
ibs: DEF_BLOCK_SIZE,
obs: DEF_BLOCK_SIZE,
cbs: 0,
seek: 0,
skip: 0,
count: 0,
conversions: Vec::new(),
noerror: false,
notrunc: false,
cbs: Default::default(),
seek: Default::default(),
skip: Default::default(),
count: Default::default(),
conversions: Default::default(),
noerror: Default::default(),
notrunc: Default::default(),
}
}
}
Expand Down Expand Up @@ -341,7 +341,7 @@ fn parse_block_size(s: &str) -> Result<usize, Box<dyn std::error::Error>> {
}

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

for arg in args {
// Split arg into option and argument
Expand Down
11 changes: 2 additions & 9 deletions file/tee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,11 @@ struct TeeFile {
f: File,
}

#[derive(Default)]
struct TeeInfo {
outputs: Vec<TeeFile>,
}

impl TeeInfo {
fn new() -> TeeInfo {
TeeInfo {
outputs: Vec::new(),
}
}
}

fn open_outputs(args: &Args, info: &mut TeeInfo) -> io::Result<()> {
for filename in &args.files {
let f_res = OpenOptions::new()
Expand Down Expand Up @@ -113,7 +106,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
}
}

let mut state = TeeInfo::new();
let mut state = TeeInfo::default();

open_outputs(&args, &mut state)?;
tee_stdin(&mut state)?;
Expand Down
64 changes: 14 additions & 50 deletions plib/src/modestr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ use libc::{
S_IWUSR, S_IXGRP, S_IXOTH, S_IXUSR,
};

#[derive(PartialEq, Debug)]
#[derive(PartialEq, Debug, Default)]
pub enum ChmodActionOp {
Add,
Remove,
#[default]
Set,
}

#[derive(Debug)]
#[derive(Debug, Default)]
pub struct ChmodAction {
pub op: ChmodActionOp,

Expand All @@ -37,25 +38,7 @@ pub struct ChmodAction {
dirty: bool,
}

impl ChmodAction {
pub fn new() -> ChmodAction {
ChmodAction {
op: ChmodActionOp::Set,
copy_user: false,
copy_group: false,
copy_others: false,
read: false,
write: false,
execute: false,
execute_dir: false,
setuid: false,
sticky: false,
dirty: false,
}
}
}

#[derive(Debug)]
#[derive(Debug, Default)]
pub struct ChmodClause {
// wholist
pub user: bool,
Expand All @@ -68,39 +51,20 @@ pub struct ChmodClause {
dirty: bool,
}

impl ChmodClause {
pub fn new() -> ChmodClause {
ChmodClause {
user: false,
group: false,
others: false,
actions: Vec::new(),
dirty: false,
}
}
}

#[derive(Debug)]
#[derive(Debug, Default)]
pub struct ChmodSymbolic {
pub clauses: Vec<ChmodClause>,
}

impl ChmodSymbolic {
pub fn new() -> ChmodSymbolic {
ChmodSymbolic {
clauses: Vec::new(),
}
}
}

#[derive(Debug)]
pub enum ChmodMode {
Absolute(u32),
Symbolic(ChmodSymbolic),
}

#[derive(Debug)]
#[derive(Debug, Default)]
enum ParseState {
#[default]
Wholist,
Actionlist,
ListOrCopy,
Expand All @@ -114,11 +78,11 @@ pub fn parse(mode: &str) -> Result<ChmodMode, String> {
return Ok(ChmodMode::Absolute(m));
}

let mut state = ParseState::Wholist;
let mut done_with_char;
let mut symbolic = ChmodSymbolic::new();
let mut clause = ChmodClause::new();
let mut action = ChmodAction::new();
let mut state = ParseState::default();
let mut symbolic = ChmodSymbolic::default();
let mut clause = ChmodClause::default();
let mut action = ChmodAction::default();

for c in mode.chars() {
done_with_char = false;
Expand Down Expand Up @@ -156,7 +120,7 @@ pub fn parse(mode: &str) -> Result<ChmodMode, String> {
action.dirty = false;
done_with_char = false;
symbolic.clauses.push(clause);
clause = ChmodClause::new();
clause = ChmodClause::default();
state = ParseState::NextClause;
}
}
Expand All @@ -177,7 +141,7 @@ pub fn parse(mode: &str) -> Result<ChmodMode, String> {
done_with_char = false;
clause.actions.push(action);
clause.dirty = true;
action = ChmodAction::new();
action = ChmodAction::default();
state = ParseState::Actionlist;
}
}
Expand All @@ -196,7 +160,7 @@ pub fn parse(mode: &str) -> Result<ChmodMode, String> {
done_with_char = false;
clause.actions.push(action);
clause.dirty = true;
action = ChmodAction::new();
action = ChmodAction::default();
state = ParseState::Actionlist;
}
}
Expand Down
12 changes: 7 additions & 5 deletions text/asa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,16 @@ struct AsaState {
lines: Vec<String>,
}

impl AsaState {
fn new() -> AsaState {
AsaState {
impl Default for AsaState {
fn default() -> Self {
Self {
first_line: true,
lines: Vec::new(),
lines: Default::default(),
}
}
}

impl AsaState {
fn push(&mut self, line: &str) {
self.lines.push(line.to_string());
if self.first_line {
Expand Down Expand Up @@ -69,7 +71,7 @@ impl AsaState {
fn asa_file(pathname: &PathBuf) -> io::Result<()> {
let mut reader = plib::io::input_reader(pathname, false)?;
let mut line_no: usize = 0;
let mut state = AsaState::new();
let mut state = AsaState::default();

loop {
line_no += 1;
Expand Down
Loading