diff --git a/src/cat/cat.rs b/src/cat/cat.rs index 37762fb8e..f3ea3676b 100755 --- a/src/cat/cat.rs +++ b/src/cat/cat.rs @@ -100,7 +100,7 @@ struct OutputOptions { /// Represents an open file handle, stream, or other device struct InputHandle { - reader: Box, + reader: Box, is_interactive: bool, } @@ -241,7 +241,7 @@ fn open(path: &str) -> CatResult { if path == "-" { let stdin = stdin(); return Ok(InputHandle { - reader: Box::new(stdin) as Box, + reader: Box::new(stdin) as Box, is_interactive: is_stdin_interactive(), }); } @@ -253,14 +253,14 @@ fn open(path: &str) -> CatResult { let socket = UnixStream::connect(path).context(path)?; socket.shutdown(Shutdown::Write).context(path)?; Ok(InputHandle { - reader: Box::new(socket) as Box, + reader: Box::new(socket) as Box, is_interactive: false, }) } _ => { let file = File::open(path).context(path)?; Ok(InputHandle { - reader: Box::new(file) as Box, + reader: Box::new(file) as Box, is_interactive: false, }) } diff --git a/src/cksum/cksum.rs b/src/cksum/cksum.rs index 08b56b7d3..e03cea4e7 100644 --- a/src/cksum/cksum.rs +++ b/src/cksum/cksum.rs @@ -55,7 +55,7 @@ fn cksum(fname: &str) -> io::Result<(u32, usize)> { let mut size = 0usize; let file; - let mut rd: Box = match fname { + let mut rd: Box = match fname { "-" => Box::new(stdin()), _ => { file = File::open(&Path::new(fname))?; diff --git a/src/date/date.rs b/src/date/date.rs index db81f2fd6..f07a5e756 100644 --- a/src/date/date.rs +++ b/src/date/date.rs @@ -137,7 +137,7 @@ pub fn uumain(args: Vec) -> i32 { } // Iterate over all dates - whether it's a single date or a file. - let dates: Box> = match settings.date_source { + let dates: Box> = match settings.date_source { DateSource::Custom(ref input) => { let date = parse_date(input.clone()); let iter = std::iter::once(date); diff --git a/src/du/du.rs b/src/du/du.rs index a3fc1dd1e..fad2df371 100644 --- a/src/du/du.rs +++ b/src/du/du.rs @@ -142,7 +142,7 @@ fn du( options: &Options, depth: usize, inodes: &mut HashSet, -) -> Box> { +) -> Box> { let mut stats = vec![]; let mut futures = vec![]; diff --git a/src/expand/expand.rs b/src/expand/expand.rs index 7430aa1ea..b117ecfc3 100644 --- a/src/expand/expand.rs +++ b/src/expand/expand.rs @@ -128,16 +128,16 @@ pub fn uumain(args: Vec) -> i32 { 0 } -fn open(path: String) -> BufReader> { +fn open(path: String) -> BufReader> { let file_buf; if path == "-" { - BufReader::new(Box::new(stdin()) as Box) + BufReader::new(Box::new(stdin()) as Box) } else { file_buf = match File::open(&path[..]) { Ok(a) => a, Err(e) => crash!(1, "{}: {}\n", &path[..], e), }; - BufReader::new(Box::new(file_buf) as Box) + BufReader::new(Box::new(file_buf) as Box) } } diff --git a/src/fmt/fmt.rs b/src/fmt/fmt.rs index 816e47ede..a81ad2cf5 100644 --- a/src/fmt/fmt.rs +++ b/src/fmt/fmt.rs @@ -38,7 +38,7 @@ static SYNTAX: &str = "[OPTION]... [FILE]..."; static SUMMARY: &str = "Reformat paragraphs from input files (or stdin) to stdout."; static LONG_HELP: &str = ""; -pub type FileOrStdReader = BufReader>; +pub type FileOrStdReader = BufReader>; pub struct FmtOptions { crown: bool, tagged: bool, @@ -179,9 +179,9 @@ pub fn uumain(args: Vec) -> i32 { for i in files.iter().map(|x| &x[..]) { let mut fp = match i { - "-" => BufReader::new(Box::new(stdin()) as Box), + "-" => BufReader::new(Box::new(stdin()) as Box), _ => match File::open(i) { - Ok(f) => BufReader::new(Box::new(f) as Box), + Ok(f) => BufReader::new(Box::new(f) as Box), Err(e) => { show_warning!("{}: {}", i, e); continue; diff --git a/src/fold/fold.rs b/src/fold/fold.rs index 8e083df32..f4a26f4e4 100644 --- a/src/fold/fold.rs +++ b/src/fold/fold.rs @@ -89,10 +89,10 @@ fn fold(filenames: Vec, bytes: bool, spaces: bool, width: usize) { let mut file_buf; let buffer = BufReader::new(if filename == "-" { stdin_buf = stdin(); - &mut stdin_buf as &mut Read + &mut stdin_buf as &mut dyn Read } else { file_buf = safe_unwrap!(File::open(Path::new(filename))); - &mut file_buf as &mut Read + &mut file_buf as &mut dyn Read }); fold_file(buffer, bytes, spaces, width); } diff --git a/src/hashsum/hashsum.rs b/src/hashsum/hashsum.rs index a902290c4..f32f3e307 100644 --- a/src/hashsum/hashsum.rs +++ b/src/hashsum/hashsum.rs @@ -51,23 +51,23 @@ fn is_custom_binary(program: &str) -> bool { fn detect_algo( program: &str, matches: &getopts::Matches, -) -> (&'static str, Box, usize) { - let mut alg: Option> = None; +) -> (&'static str, Box, usize) { + let mut alg: Option> = None; let mut name: &'static str = ""; let mut output_bits = 0; match program { - "md5sum" => ("MD5", Box::new(Md5::new()) as Box, 128), - "sha1sum" => ("SHA1", Box::new(Sha1::new()) as Box, 160), - "sha224sum" => ("SHA224", Box::new(Sha224::new()) as Box, 224), - "sha256sum" => ("SHA256", Box::new(Sha256::new()) as Box, 256), - "sha384sum" => ("SHA384", Box::new(Sha384::new()) as Box, 384), - "sha512sum" => ("SHA512", Box::new(Sha512::new()) as Box, 512), + "md5sum" => ("MD5", Box::new(Md5::new()) as Box, 128), + "sha1sum" => ("SHA1", Box::new(Sha1::new()) as Box, 160), + "sha224sum" => ("SHA224", Box::new(Sha224::new()) as Box, 224), + "sha256sum" => ("SHA256", Box::new(Sha256::new()) as Box, 256), + "sha384sum" => ("SHA384", Box::new(Sha384::new()) as Box, 384), + "sha512sum" => ("SHA512", Box::new(Sha512::new()) as Box, 512), "sha3sum" => match matches.opt_str("bits") { Some(bits_str) => match usize::from_str_radix(&bits_str, 10) { - Ok(224) => ("SHA3-224", Box::new(Sha3_224::new()) as Box, 224), - Ok(256) => ("SHA3-256", Box::new(Sha3_256::new()) as Box, 256), - Ok(384) => ("SHA3-384", Box::new(Sha3_384::new()) as Box, 384), - Ok(512) => ("SHA3-512", Box::new(Sha3_512::new()) as Box, 512), + Ok(224) => ("SHA3-224", Box::new(Sha3_224::new()) as Box, 224), + Ok(256) => ("SHA3-256", Box::new(Sha3_256::new()) as Box, 256), + Ok(384) => ("SHA3-384", Box::new(Sha3_384::new()) as Box, 384), + Ok(512) => ("SHA3-512", Box::new(Sha3_512::new()) as Box, 512), Ok(_) => crash!( 1, "Invalid output size for SHA3 (expected 224, 256, 384, or 512)" @@ -76,20 +76,20 @@ fn detect_algo( }, None => crash!(1, "--bits required for SHA3"), }, - "sha3-224sum" => ("SHA3-224", Box::new(Sha3_224::new()) as Box, 224), - "sha3-256sum" => ("SHA3-256", Box::new(Sha3_256::new()) as Box, 256), - "sha3-384sum" => ("SHA3-384", Box::new(Sha3_384::new()) as Box, 384), - "sha3-512sum" => ("SHA3-512", Box::new(Sha3_512::new()) as Box, 512), + "sha3-224sum" => ("SHA3-224", Box::new(Sha3_224::new()) as Box, 224), + "sha3-256sum" => ("SHA3-256", Box::new(Sha3_256::new()) as Box, 256), + "sha3-384sum" => ("SHA3-384", Box::new(Sha3_384::new()) as Box, 384), + "sha3-512sum" => ("SHA3-512", Box::new(Sha3_512::new()) as Box, 512), "shake128sum" => match matches.opt_str("bits") { Some(bits_str) => match usize::from_str_radix(&bits_str, 10) { - Ok(bits) => ("SHAKE128", Box::new(Shake128::new()) as Box, bits), + Ok(bits) => ("SHAKE128", Box::new(Shake128::new()) as Box, bits), Err(err) => crash!(1, "{}", err), }, None => crash!(1, "--bits required for SHAKE-128"), }, "shake256sum" => match matches.opt_str("bits") { Some(bits_str) => match usize::from_str_radix(&bits_str, 10) { - Ok(bits) => ("SHAKE256", Box::new(Shake256::new()) as Box, bits), + Ok(bits) => ("SHAKE256", Box::new(Shake256::new()) as Box, bits), Err(err) => crash!(1, "{}", err), }, None => crash!(1, "--bits required for SHAKE-256"), @@ -127,22 +127,22 @@ fn detect_algo( Some(bits_str) => match usize::from_str_radix(&bits_str, 10) { Ok(224) => set_or_crash( "SHA3-224", - Box::new(Sha3_224::new()) as Box, + Box::new(Sha3_224::new()) as Box, 224, ), Ok(256) => set_or_crash( "SHA3-256", - Box::new(Sha3_256::new()) as Box, + Box::new(Sha3_256::new()) as Box, 256, ), Ok(384) => set_or_crash( "SHA3-384", - Box::new(Sha3_384::new()) as Box, + Box::new(Sha3_384::new()) as Box, 384, ), Ok(512) => set_or_crash( "SHA3-512", - Box::new(Sha3_512::new()) as Box, + Box::new(Sha3_512::new()) as Box, 512, ), Ok(_) => crash!( @@ -369,7 +369,7 @@ Compute and check message digests.", fn hashsum( algoname: &str, - mut digest: Box, + mut digest: Box, files: Vec, binary: bool, check: bool, @@ -389,10 +389,10 @@ fn hashsum( let file_buf; let mut file = BufReader::new(if filename == "-" { stdin_buf = stdin(); - Box::new(stdin_buf) as Box + Box::new(stdin_buf) as Box } else { file_buf = safe_unwrap!(File::open(filename)); - Box::new(file_buf) as Box + Box::new(file_buf) as Box }); if check { // Set up Regexes for line validation and parsing @@ -440,7 +440,7 @@ fn hashsum( }, }; let f = safe_unwrap!(File::open(ck_filename)); - let mut ckf = BufReader::new(Box::new(f) as Box); + let mut ckf = BufReader::new(Box::new(f) as Box); let real_sum = safe_unwrap!(digest_reader( &mut digest, &mut ckf, @@ -482,7 +482,7 @@ fn hashsum( } fn digest_reader<'a, T: Read>( - digest: &mut Box, + digest: &mut Box, reader: &mut BufReader, binary: bool, output_bits: usize, diff --git a/src/join/join.rs b/src/join/join.rs index 6d2ccb7ed..9915e5130 100755 --- a/src/join/join.rs +++ b/src/join/join.rs @@ -235,7 +235,7 @@ struct State<'a> { file_name: &'a str, file_num: FileNum, print_unpaired: bool, - lines: Lines>, + lines: Lines>, seq: Vec, max_fields: Option, line_num: usize, @@ -251,10 +251,10 @@ impl<'a> State<'a> { print_unpaired: FileNum, ) -> State<'a> { let f = if name == "-" { - Box::new(stdin.lock()) as Box + Box::new(stdin.lock()) as Box } else { match File::open(name) { - Ok(file) => Box::new(BufReader::new(file)) as Box, + Ok(file) => Box::new(BufReader::new(file)) as Box, Err(err) => crash!(1, "{}: {}", name, err), } }; diff --git a/src/od/multifilereader.rs b/src/od/multifilereader.rs index 20dfa1ae1..b53216cab 100644 --- a/src/od/multifilereader.rs +++ b/src/od/multifilereader.rs @@ -8,13 +8,13 @@ pub enum InputSource<'a> { FileName(&'a str), Stdin, #[allow(dead_code)] - Stream(Box), + Stream(Box), } // MultifileReader - concatenate all our input, file or stdin. pub struct MultifileReader<'a> { ni: Vec>, - curr_file: Option>, + curr_file: Option>, any_err: bool, } diff --git a/src/od/output_info.rs b/src/od/output_info.rs index 2ce6596d2..eaf46296c 100644 --- a/src/od/output_info.rs +++ b/src/od/output_info.rs @@ -138,7 +138,7 @@ impl OutputInfo { /// This algorithm assumes the size of all types is a power of 2 (1, 2, 4, 8, 16, ...) /// Increase MAX_BYTES_PER_UNIT to allow larger types. fn calculate_alignment( - sf: &TypeSizeInfo, + sf: &dyn TypeSizeInfo, byte_size_block: usize, print_width_block: usize, ) -> [usize; MAX_BYTES_PER_UNIT] { diff --git a/src/od/parse_inputs.rs b/src/od/parse_inputs.rs index 63af6eba5..b1ab17427 100644 --- a/src/od/parse_inputs.rs +++ b/src/od/parse_inputs.rs @@ -38,7 +38,7 @@ pub enum CommandLineInputs { /// Offset and label are specified in bytes. /// '-' is used as filename if stdin is meant. This is also returned if /// there is no input, as stdin is the default input. -pub fn parse_inputs(matches: &CommandLineOpts) -> Result { +pub fn parse_inputs(matches: &dyn CommandLineOpts) -> Result { let mut input_strings: Vec = matches.inputs(); if matches.opts_present(&["traditional"]) { diff --git a/src/paste/paste.rs b/src/paste/paste.rs index 8ad29568b..bffe0b96f 100644 --- a/src/paste/paste.rs +++ b/src/paste/paste.rs @@ -68,14 +68,14 @@ FILE, separated by TABs, to standard output.", } fn paste(filenames: Vec, serial: bool, delimiters: String) { - let mut files: Vec>> = filenames + let mut files: Vec>> = filenames .into_iter() .map(|name| { BufReader::new(if name == "-" { - Box::new(stdin()) as Box + Box::new(stdin()) as Box } else { let r = crash_if_err!(1, File::open(Path::new(&name))); - Box::new(r) as Box + Box::new(r) as Box }) }) .collect(); diff --git a/src/printf/memo.rs b/src/printf/memo.rs index e5a05cf0e..e006f22b5 100644 --- a/src/printf/memo.rs +++ b/src/printf/memo.rs @@ -14,7 +14,7 @@ use tokenize::unescaped_text::UnescapedText; use tokenize::sub::Sub; pub struct Memo { - tokens: Vec>, + tokens: Vec>, } fn warn_excess_args(first_arg: &str) { @@ -27,7 +27,7 @@ fn warn_excess_args(first_arg: &str) { impl Memo { pub fn new(pf_string: &String, pf_args_it: &mut Peekable>) -> Memo { let mut pm = Memo { tokens: Vec::new() }; - let mut tmp_token: Option>; + let mut tmp_token: Option>; let mut it = put_back_n(pf_string.chars()); let mut has_sub = false; loop { diff --git a/src/printf/tokenize/num_format/formatters/base_conv/mod.rs b/src/printf/tokenize/num_format/formatters/base_conv/mod.rs index 5e46a6c51..e2b8f0b0a 100644 --- a/src/printf/tokenize/num_format/formatters/base_conv/mod.rs +++ b/src/printf/tokenize/num_format/formatters/base_conv/mod.rs @@ -240,7 +240,7 @@ pub fn base_conv_float(src: &Vec, radix_src: u8, radix_dest: u8) -> f64 { r } -pub fn str_to_arrnum(src: &str, radix_def_src: &RadixDef) -> Vec { +pub fn str_to_arrnum(src: &str, radix_def_src: &dyn RadixDef) -> Vec { let mut intermed_in: Vec = Vec::new(); for c in src.chars() { match radix_def_src.from_char(c) { @@ -253,7 +253,7 @@ pub fn str_to_arrnum(src: &str, radix_def_src: &RadixDef) -> Vec { intermed_in } -pub fn arrnum_to_str(src: &Vec, radix_def_dest: &RadixDef) -> String { +pub fn arrnum_to_str(src: &Vec, radix_def_dest: &dyn RadixDef) -> String { let mut str_out = String::new(); for u in src.iter() { match radix_def_dest.from_u8(u.clone()) { @@ -267,7 +267,11 @@ pub fn arrnum_to_str(src: &Vec, radix_def_dest: &RadixDef) -> String { } #[allow(unused_variables)] -pub fn base_conv_str(src: &str, radix_def_src: &RadixDef, radix_def_dest: &RadixDef) -> String { +pub fn base_conv_str( + src: &str, + radix_def_src: &dyn RadixDef, + radix_def_dest: &dyn RadixDef, +) -> String { let intermed_in: Vec = str_to_arrnum(src, radix_def_src); let intermed_out = base_conv_vec( &intermed_in, diff --git a/src/printf/tokenize/num_format/num_format.rs b/src/printf/tokenize/num_format/num_format.rs index 911fabb6a..ba9c78d85 100644 --- a/src/printf/tokenize/num_format/num_format.rs +++ b/src/printf/tokenize/num_format/num_format.rs @@ -210,7 +210,7 @@ pub fn num_format(field: &FormatField, in_str_opt: Option<&String>) -> Option = match *field.field_type { + let fmtr: Box = match *field.field_type { FieldType::Intf => Box::new(Intf::new()), FieldType::Floatf => Box::new(Floatf::new()), FieldType::CninetyNineHexFloatf => Box::new(CninetyNineHexFloatf::new()), diff --git a/src/printf/tokenize/sub.rs b/src/printf/tokenize/sub.rs index 7e52757d4..cc0b1d3f2 100644 --- a/src/printf/tokenize/sub.rs +++ b/src/printf/tokenize/sub.rs @@ -116,20 +116,20 @@ impl SubParser { fn from_it( it: &mut PutBackN, args: &mut Peekable>, - ) -> Option> { + ) -> Option> { let mut parser = SubParser::new(); if parser.sub_vals_retrieved(it) { - let t: Box = SubParser::build_token(parser); + let t: Box = SubParser::build_token(parser); t.print(args); Some(t) } else { None } } - fn build_token(parser: SubParser) -> Box { + fn build_token(parser: SubParser) -> Box { // not a self method so as to allow move of subparser vals. // return new Sub struct as token - let t: Box = Box::new(Sub::new( + let t: Box = Box::new(Sub::new( if parser.min_width_is_asterisk { CanAsterisk::Asterisk } else { @@ -317,7 +317,7 @@ impl token::Tokenizer for Sub { fn from_it( it: &mut PutBackN, args: &mut Peekable>, - ) -> Option> { + ) -> Option> { SubParser::from_it(it, args) } } diff --git a/src/printf/tokenize/token.rs b/src/printf/tokenize/token.rs index 378702682..78009dd91 100644 --- a/src/printf/tokenize/token.rs +++ b/src/printf/tokenize/token.rs @@ -1,10 +1,9 @@ //! Traits and enums dealing with Tokenization of printf Format String -#[allow(unused_must_use)] - -use std::iter::Peekable; -use std::str::Chars; -use std::slice::Iter; use itertools::PutBackN; +#[allow(unused_must_use)] +use std::iter::Peekable; +use std::slice::Iter; +use std::str::Chars; // A token object is an object that can print the expected output // of a contiguous segment of the format string, and @@ -26,5 +25,8 @@ pub trait Token { // a number of arguments equal to the number of argument-using tokens pub trait Tokenizer { - fn from_it(it: &mut PutBackN, args: &mut Peekable>) -> Option>; + fn from_it( + it: &mut PutBackN, + args: &mut Peekable>, + ) -> Option>; } diff --git a/src/printf/tokenize/unescaped_text.rs b/src/printf/tokenize/unescaped_text.rs index 3ea0038b1..2ccbf56fc 100644 --- a/src/printf/tokenize/unescaped_text.rs +++ b/src/printf/tokenize/unescaped_text.rs @@ -3,14 +3,14 @@ //! and escaped character literals (of allowed escapes), //! into an unescaped text byte array -use std::iter::Peekable; -use std::slice::Iter; -use std::str::Chars; -use std::char::from_u32; -use std::process::exit; +use super::token; use cli; use itertools::PutBackN; -use super::token; +use std::char::from_u32; +use std::iter::Peekable; +use std::process::exit; +use std::slice::Iter; +use std::str::Chars; pub struct UnescapedText(Vec); impl UnescapedText { @@ -173,7 +173,10 @@ impl UnescapedText { // and return a wrapper around a Vec of unescaped bytes // break on encounter of sub symbol ('%[^%]') unless called // through %b subst. - pub fn from_it_core(it: &mut PutBackN, subs_mode: bool) -> Option> { + pub fn from_it_core( + it: &mut PutBackN, + subs_mode: bool, + ) -> Option> { let mut addchar = false; let mut new_text = UnescapedText::new(); let mut tmp_str = String::new(); @@ -241,7 +244,7 @@ impl token::Tokenizer for UnescapedText { fn from_it( it: &mut PutBackN, args: &mut Peekable>, - ) -> Option> { + ) -> Option> { UnescapedText::from_it_core(it, false) } } diff --git a/src/ptx/ptx.rs b/src/ptx/ptx.rs index cc30242d5..8573b65ab 100644 --- a/src/ptx/ptx.rs +++ b/src/ptx/ptx.rs @@ -200,7 +200,7 @@ fn read_input(input_files: &[String], config: &Config) -> HashMap> = BufReader::new(if filename == "-" { + let reader: BufReader> = BufReader::new(if filename == "-" { Box::new(stdin()) } else { let file = crash_if_err!(1, File::open(filename)); @@ -470,7 +470,7 @@ fn write_traditional_output( words: &BTreeSet, output_filename: &str, ) { - let mut writer: BufWriter> = BufWriter::new(if output_filename == "-" { + let mut writer: BufWriter> = BufWriter::new(if output_filename == "-" { Box::new(stdout()) } else { let file = crash_if_err!(1, File::create(output_filename)); diff --git a/src/shuf/shuf.rs b/src/shuf/shuf.rs index 6f5e0ee28..ee0d1c91c 100644 --- a/src/shuf/shuf.rs +++ b/src/shuf/shuf.rs @@ -147,10 +147,10 @@ With no FILE, or when FILE is -, read standard input.", fn read_input_file(filename: &str) -> Vec { let mut file = BufReader::new(if filename == "-" { - Box::new(stdin()) as Box + Box::new(stdin()) as Box } else { match File::open(filename) { - Ok(f) => Box::new(f) as Box, + Ok(f) => Box::new(f) as Box, Err(e) => crash!(1, "failed to open '{}': {}", filename, e), } }); @@ -206,9 +206,9 @@ fn shuf_bytes( random: Option, ) { let mut output = BufWriter::new(match output { - None => Box::new(stdout()) as Box, + None => Box::new(stdout()) as Box, Some(s) => match File::create(&s[..]) { - Ok(f) => Box::new(f) as Box, + Ok(f) => Box::new(f) as Box, Err(e) => crash!(1, "failed to open '{}' for writing: {}", &s[..], e), }, }); diff --git a/src/sort/sort.rs b/src/sort/sort.rs index c21802d49..81ea58a26 100644 --- a/src/sort/sort.rs +++ b/src/sort/sort.rs @@ -69,7 +69,7 @@ impl Default for Settings { } struct MergeableFile<'a> { - lines: Lines>>, + lines: Lines>>, current_line: String, settings: &'a Settings, } @@ -109,7 +109,7 @@ impl<'a> FileMerger<'a> { settings: settings, } } - fn push_file(&mut self, mut lines: Lines>>) { + fn push_file(&mut self, mut lines: Lines>>) { match lines.next() { Some(Ok(next_line)) => { let mergeable_file = MergeableFile { @@ -313,7 +313,7 @@ fn exec(files: Vec, settings: &Settings) -> i32 { 0 } -fn exec_check_file(lines: Lines>>, settings: &Settings) -> i32 { +fn exec_check_file(lines: Lines>>, settings: &Settings) -> i32 { // errors yields the line before each disorder, // plus the last line (quirk of .coalesce()) let unwrapped_lines = lines.filter_map(|maybe_line| { @@ -507,15 +507,15 @@ fn print_sorted>(iter: T, outfile: &Option) where S: std::fmt::Display, { - let mut file: Box = match *outfile { + let mut file: Box = match *outfile { Some(ref filename) => match File::create(Path::new(&filename)) { - Ok(f) => Box::new(BufWriter::new(f)) as Box, + Ok(f) => Box::new(BufWriter::new(f)) as Box, Err(e) => { show_error!("sort: {0}: {1}", filename, e.to_string()); panic!("Could not open output file"); } }, - None => Box::new(stdout()) as Box, + None => Box::new(stdout()) as Box, }; for line in iter { @@ -531,14 +531,14 @@ where } // from cat.rs -fn open(path: &str) -> Option<(Box, bool)> { +fn open(path: &str) -> Option<(Box, bool)> { if path == "-" { let stdin = stdin(); - return Some((Box::new(stdin) as Box, is_stdin_interactive())); + return Some((Box::new(stdin) as Box, is_stdin_interactive())); } match File::open(Path::new(path)) { - Ok(f) => Some((Box::new(f) as Box, false)), + Ok(f) => Some((Box::new(f) as Box, false)), Err(e) => { show_error!("sort: {0}: {1}", path, e.to_string()); None diff --git a/src/split/split.rs b/src/split/split.rs index e32467bb2..8104f8a08 100644 --- a/src/split/split.rs +++ b/src/split/split.rs @@ -159,7 +159,7 @@ struct LineSplitter { } impl LineSplitter { - fn new(settings: &Settings) -> Box { + fn new(settings: &Settings) -> Box { let n = match settings.strategy_param.parse() { Ok(a) => a, Err(e) => crash!(1, "invalid number of lines: {}", e), @@ -167,7 +167,7 @@ impl LineSplitter { Box::new(LineSplitter { saved_lines_to_write: n, lines_to_write: n, - }) as Box + }) as Box } } @@ -190,7 +190,7 @@ struct ByteSplitter { } impl ByteSplitter { - fn new(settings: &Settings) -> Box { + fn new(settings: &Settings) -> Box { let mut strategy_param: Vec = settings.strategy_param.chars().collect(); let suffix = strategy_param.pop().unwrap(); let multiplier = match suffix { @@ -221,7 +221,7 @@ impl ByteSplitter { bytes_to_write: n * multiplier, break_on_line_end: settings.strategy == "b", require_whole_line: false, - }) as Box + }) as Box } } @@ -279,7 +279,7 @@ fn num_prefix(i: usize, width: usize) -> String { fn split(settings: &Settings) -> i32 { let mut reader = BufReader::new(if settings.input == "-" { - Box::new(stdin()) as Box + Box::new(stdin()) as Box } else { let r = match File::open(Path::new(&settings.input)) { Ok(a) => a, @@ -289,10 +289,10 @@ fn split(settings: &Settings) -> i32 { settings.input ), }; - Box::new(r) as Box + Box::new(r) as Box }); - let mut splitter: Box = match settings.strategy.as_ref() { + let mut splitter: Box = match settings.strategy.as_ref() { "l" => LineSplitter::new(settings), "b" | "C" => ByteSplitter::new(settings), a => crash!(1, "strategy {} not supported", a), @@ -303,7 +303,7 @@ fn split(settings: &Settings) -> i32 { request_new_file: true, // Request new file }; - let mut writer = BufWriter::new(Box::new(stdout()) as Box); + let mut writer = BufWriter::new(Box::new(stdout()) as Box); let mut fileno = 0; loop { if control.current_line.chars().count() == 0 { @@ -333,7 +333,7 @@ fn split(settings: &Settings) -> i32 { .create(true) .open(Path::new(&filename)) .unwrap(), - ) as Box); + ) as Box); control.request_new_file = false; if settings.verbose { println!("creating file '{}'", filename); diff --git a/src/sum/sum.rs b/src/sum/sum.rs index 3f506ab40..1fd7a6202 100644 --- a/src/sum/sum.rs +++ b/src/sum/sum.rs @@ -21,7 +21,7 @@ use std::path::Path; static NAME: &str = "sum"; static VERSION: &str = env!("CARGO_PKG_VERSION"); -fn bsd_sum(mut reader: Box) -> (usize, u16) { +fn bsd_sum(mut reader: Box) -> (usize, u16) { let mut buf = [0; 1024]; let mut blocks_read = 0; let mut checksum: u16 = 0; @@ -41,7 +41,7 @@ fn bsd_sum(mut reader: Box) -> (usize, u16) { (blocks_read, checksum) } -fn sysv_sum(mut reader: Box) -> (usize, u16) { +fn sysv_sum(mut reader: Box) -> (usize, u16) { let mut buf = [0; 512]; let mut blocks_read = 0; let mut ret = 0u32; @@ -64,12 +64,12 @@ fn sysv_sum(mut reader: Box) -> (usize, u16) { (blocks_read, ret as u16) } -fn open(name: &str) -> Result> { +fn open(name: &str) -> Result> { match name { - "-" => Ok(Box::new(stdin()) as Box), + "-" => Ok(Box::new(stdin()) as Box), _ => { let f = File::open(&Path::new(name))?; - Ok(Box::new(f) as Box) + Ok(Box::new(f) as Box) } } } diff --git a/src/tac/tac.rs b/src/tac/tac.rs index bc14d926b..eb6786359 100644 --- a/src/tac/tac.rs +++ b/src/tac/tac.rs @@ -91,10 +91,10 @@ fn tac(filenames: Vec, before: bool, _: bool, separator: &str) { for filename in &filenames { let mut file = BufReader::new(if filename == "-" { - Box::new(stdin()) as Box + Box::new(stdin()) as Box } else { match File::open(filename) { - Ok(f) => Box::new(f) as Box, + Ok(f) => Box::new(f) as Box, Err(e) => { show_warning!("failed to open '{}' for reading: {}", filename, e); continue; diff --git a/src/tee/tee.rs b/src/tee/tee.rs index dfc72ef74..de77d8555 100644 --- a/src/tee/tee.rs +++ b/src/tee/tee.rs @@ -86,7 +86,7 @@ fn exec(options: Options) -> Result<()> { } fn tee(options: Options) -> Result<()> { - let mut writers: Vec> = options + let mut writers: Vec> = options .files .clone() .into_iter() @@ -95,7 +95,7 @@ fn tee(options: Options) -> Result<()> { writers.push(Box::new(stdout())); let output = &mut MultiWriter { writers }; let input = &mut NamedReader { - inner: Box::new(stdin()) as Box, + inner: Box::new(stdin()) as Box, }; if copy(input, output).is_err() || output.flush().is_err() { Err(Error::new(ErrorKind::Other, "")) @@ -104,9 +104,9 @@ fn tee(options: Options) -> Result<()> { } } -fn open(name: String, append: bool) -> Box { +fn open(name: String, append: bool) -> Box { let path = PathBuf::from(name); - let inner: Box = { + let inner: Box = { let mut options = OpenOptions::new(); let mode = if append { options.append(true) @@ -121,11 +121,11 @@ fn open(name: String, append: bool) -> Box { Box::new(NamedWriter { inner: inner, path: path, - }) as Box + }) as Box } struct MultiWriter { - writers: Vec>, + writers: Vec>, } impl Write for MultiWriter { @@ -145,7 +145,7 @@ impl Write for MultiWriter { } struct NamedWriter { - inner: Box, + inner: Box, path: PathBuf, } @@ -153,7 +153,7 @@ impl Write for NamedWriter { fn write(&mut self, buf: &[u8]) -> Result { match self.inner.write(buf) { Err(f) => { - self.inner = Box::new(sink()) as Box; + self.inner = Box::new(sink()) as Box; warn(format!("{}: {}", self.path.display(), f.to_string()).as_ref()); Err(f) } @@ -164,7 +164,7 @@ impl Write for NamedWriter { fn flush(&mut self) -> Result<()> { match self.inner.flush() { Err(f) => { - self.inner = Box::new(sink()) as Box; + self.inner = Box::new(sink()) as Box; warn(format!("{}: {}", self.path.display(), f.to_string()).as_ref()); Err(f) } @@ -174,7 +174,7 @@ impl Write for NamedWriter { } struct NamedReader { - inner: Box, + inner: Box, } impl Read for NamedReader { diff --git a/src/tr/tr.rs b/src/tr/tr.rs index 1fe08d454..c8e28c774 100644 --- a/src/tr/tr.rs +++ b/src/tr/tr.rs @@ -20,9 +20,9 @@ extern crate getopts; extern crate uucore; use bit_set::BitSet; +use fnv::FnvHashMap; use getopts::Options; use std::io::{stdin, stdout, BufRead, BufWriter, Write}; -use fnv::FnvHashMap; use expand::ExpandSet; @@ -145,7 +145,11 @@ impl SymbolTranslator for TranslateOperation { } } -fn translate_input(input: &mut BufRead, output: &mut Write, translator: T) { +fn translate_input( + input: &mut dyn BufRead, + output: &mut dyn Write, + translator: T, +) { let mut buf = String::with_capacity(BUFFER_LEN + 4); let mut output_buf = String::with_capacity(BUFFER_LEN + 4); diff --git a/src/tsort/tsort.rs b/src/tsort/tsort.rs index f930e620d..72a96229d 100644 --- a/src/tsort/tsort.rs +++ b/src/tsort/tsort.rs @@ -62,7 +62,7 @@ pub fn uumain(args: Vec) -> i32 { let mut file_buf; let mut reader = BufReader::new(if input == "-" { stdin_buf = stdin(); - &mut stdin_buf as &mut Read + &mut stdin_buf as &mut dyn Read } else { file_buf = match File::open(Path::new(&input)) { Ok(a) => a, @@ -71,7 +71,7 @@ pub fn uumain(args: Vec) -> i32 { return 1; } }; - &mut file_buf as &mut Read + &mut file_buf as &mut dyn Read }); let mut g = Graph::new(); diff --git a/src/unexpand/unexpand.rs b/src/unexpand/unexpand.rs index 5df0dfda0..076a68fee 100644 --- a/src/unexpand/unexpand.rs +++ b/src/unexpand/unexpand.rs @@ -145,16 +145,16 @@ pub fn uumain(args: Vec) -> i32 { 0 } -fn open(path: String) -> BufReader> { +fn open(path: String) -> BufReader> { let file_buf; if path == "-" { - BufReader::new(Box::new(stdin()) as Box) + BufReader::new(Box::new(stdin()) as Box) } else { file_buf = match File::open(&path[..]) { Ok(a) => a, Err(e) => crash!(1, "{}: {}", &path[..], e), }; - BufReader::new(Box::new(file_buf) as Box) + BufReader::new(Box::new(file_buf) as Box) } } diff --git a/src/uniq/uniq.rs b/src/uniq/uniq.rs index f82704b8b..62db7b104 100644 --- a/src/uniq/uniq.rs +++ b/src/uniq/uniq.rs @@ -111,7 +111,7 @@ impl Uniq { fn cmp_key(&self, line: &str, mut closure: F) -> bool where - F: FnMut(&mut Iterator) -> bool, + F: FnMut(&mut dyn Iterator) -> bool, { let fields_to_check = self.skip_fields(line); let len = fields_to_check.len(); @@ -307,26 +307,26 @@ pub fn uumain(args: Vec) -> i32 { 0 } -fn open_input_file(in_file_name: String) -> BufReader> { +fn open_input_file(in_file_name: String) -> BufReader> { let in_file = if in_file_name == "-" { - Box::new(stdin()) as Box + Box::new(stdin()) as Box } else { let path = Path::new(&in_file_name[..]); let in_file = File::open(&path); let r = crash_if_err!(1, in_file); - Box::new(r) as Box + Box::new(r) as Box }; BufReader::new(in_file) } -fn open_output_file(out_file_name: String) -> BufWriter> { +fn open_output_file(out_file_name: String) -> BufWriter> { let out_file = if out_file_name == "-" { - Box::new(stdout()) as Box + Box::new(stdout()) as Box } else { let path = Path::new(&out_file_name[..]); let in_file = File::create(&path); let w = crash_if_err!(1, in_file); - Box::new(w) as Box + Box::new(w) as Box }; BufWriter::new(out_file) } diff --git a/src/wc/wc.rs b/src/wc/wc.rs index db1ee0ebd..67c120e93 100644 --- a/src/wc/wc.rs +++ b/src/wc/wc.rs @@ -258,9 +258,9 @@ fn print_stats(settings: &Settings, result: &Result, max_width: usize) { } } -fn open(path: &str) -> StdResult>, i32> { +fn open(path: &str) -> StdResult>, i32> { if "-" == path { - let reader = Box::new(stdin()) as Box; + let reader = Box::new(stdin()) as Box; return Ok(BufReader::new(reader)); } @@ -270,7 +270,7 @@ fn open(path: &str) -> StdResult>, i32> { } match File::open(&fpath) { Ok(fd) => { - let reader = Box::new(fd) as Box; + let reader = Box::new(fd) as Box; Ok(BufReader::new(reader)) } Err(e) => {