diff --git a/src/od/parse_formats.rs b/src/od/parse_formats.rs index f8c3659f0..d9731e78d 100644 --- a/src/od/parse_formats.rs +++ b/src/od/parse_formats.rs @@ -272,7 +272,7 @@ fn is_format_dump_char(ch: Option, show_ascii_dump: &mut bool) -> bool { } } -fn parse_type_string(params: &String) -> Result, String> { +fn parse_type_string(params: &str) -> Result, String> { let mut formats = Vec::new(); let mut chars = params.chars(); diff --git a/src/od/parse_inputs.rs b/src/od/parse_inputs.rs index b1ab17427..81409732e 100644 --- a/src/od/parse_inputs.rs +++ b/src/od/parse_inputs.rs @@ -131,7 +131,7 @@ pub fn parse_inputs_traditional(input_strings: Vec) -> Result Result { +pub fn parse_offset_operand(s: &str) -> Result { let mut start = 0; let mut len = s.len(); let mut radix = 8; diff --git a/src/od/parse_nrofbytes.rs b/src/od/parse_nrofbytes.rs index c934de9c5..766e0924d 100644 --- a/src/od/parse_nrofbytes.rs +++ b/src/od/parse_nrofbytes.rs @@ -1,4 +1,4 @@ -pub fn parse_number_of_bytes(s: &String) -> Result { +pub fn parse_number_of_bytes(s: &str) -> Result { let mut start = 0; let mut len = s.len(); let mut radix = 10; diff --git a/src/printf/memo.rs b/src/printf/memo.rs index e006f22b5..00d3c6300 100644 --- a/src/printf/memo.rs +++ b/src/printf/memo.rs @@ -74,9 +74,9 @@ impl Memo { tkn.print(pf_args_it); } } - pub fn run_all(pf_string: &String, pf_args: &[String]) { + pub fn run_all(pf_string: &str, pf_args: &[String]) { let mut arg_it = pf_args.iter().peekable(); - let pm = Memo::new(pf_string, &mut arg_it); + let pm = Memo::new(&pf_string.to_string(), &mut arg_it); loop { if arg_it.peek().is_none() { break; diff --git a/src/printf/tokenize/num_format/num_format.rs b/src/printf/tokenize/num_format/num_format.rs index 23ca72936..4289ec842 100644 --- a/src/printf/tokenize/num_format/num_format.rs +++ b/src/printf/tokenize/num_format/num_format.rs @@ -83,7 +83,7 @@ fn get_provided(str_in_opt: Option<&String>) -> Option { // a base, // and an offset for index after all // initial spacing, sign, base prefix, and leading zeroes -fn get_inprefix(str_in: &String, field_type: &FieldType) -> InPrefix { +fn get_inprefix(str_in: &str, field_type: &FieldType) -> InPrefix { let mut str_it = str_in.chars(); let mut ret = InPrefix { radix_in: Base::Ten, diff --git a/src/printf/tokenize/sub.rs b/src/printf/tokenize/sub.rs index 6e5311bf1..fb604bf35 100644 --- a/src/printf/tokenize/sub.rs +++ b/src/printf/tokenize/sub.rs @@ -15,12 +15,12 @@ use super::num_format::format_field::{FieldType, FormatField}; use super::num_format::num_format; // use std::collections::HashSet; -fn err_conv(sofar: &String) { +fn err_conv(sofar: &str) { cli::err_msg(&format!("%{}: invalid conversion specification", sofar)); exit(cli::EXIT_ERR); } -fn convert_asterisk_arg_int(asterisk_arg: &String) -> isize { +fn convert_asterisk_arg_int(asterisk_arg: &str) -> isize { // this is a costly way to parse the // args used for asterisk values into integers // from various bases. Actually doing it correctly @@ -32,11 +32,11 @@ fn convert_asterisk_arg_int(asterisk_arg: &String) -> isize { let field_info = FormatField { min_width: Some(0), second_field: Some(0), - orig: asterisk_arg, + orig: &asterisk_arg.to_string(), field_type: &field_type, field_char: &field_char, }; - num_format::num_format(&field_info, Some(asterisk_arg)) + num_format::num_format(&field_info, Some(&asterisk_arg.to_string())) .unwrap() .parse::() .unwrap() diff --git a/src/sort/sort.rs b/src/sort/sort.rs index 1bfa13122..54680b8a7 100644 --- a/src/sort/sort.rs +++ b/src/sort/sort.rs @@ -49,7 +49,7 @@ struct Settings { unique: bool, check: bool, ignore_case: bool, - compare_fns: Vec Ordering>, + compare_fns: Vec Ordering>, } impl Default for Settings { @@ -352,13 +352,13 @@ fn sort_by(lines: &mut Vec, settings: &Settings) { lines.sort_by(|a, b| compare_by(a, b, &settings)) } -fn compare_by(a: &String, b: &String, settings: &Settings) -> Ordering { +fn compare_by(a: &str, b: &str, settings: &Settings) -> Ordering { // Convert to uppercase if necessary let (a_upper, b_upper): (String, String); let (a, b) = if settings.ignore_case { a_upper = a.to_uppercase(); b_upper = b.to_uppercase(); - (&a_upper, &b_upper) + (&*a_upper, &*b_upper) } else { (a, b) }; @@ -402,7 +402,7 @@ fn default_compare(a: &str, b: &str) -> Ordering { /// Compares two floating point numbers, with errors being assumed to be -inf. /// Stops coercing at the first whitespace char, so 1e2 will parse as 100 but /// 1,000 will parse as -inf. -fn numeric_compare(a: &String, b: &String) -> Ordering { +fn numeric_compare(a: &str, b: &str) -> Ordering { let fa = permissive_f64_parse(a); let fb = permissive_f64_parse(b); // f64::cmp isn't implemented because NaN messes with it @@ -416,7 +416,7 @@ fn numeric_compare(a: &String, b: &String) -> Ordering { } } -fn human_numeric_convert(a: &String) -> f64 { +fn human_numeric_convert(a: &str) -> f64 { let int_iter = a.chars(); let suffix_iter = a.chars(); let int_str: String = int_iter.take_while(|c| c.is_numeric()).collect(); @@ -438,7 +438,7 @@ fn human_numeric_convert(a: &String) -> f64 { /// Compare two strings as if they are human readable sizes. /// AKA 1M > 100k -fn human_numeric_size_compare(a: &String, b: &String) -> Ordering { +fn human_numeric_size_compare(a: &str, b: &str) -> Ordering { let fa = human_numeric_convert(a); let fb = human_numeric_convert(b); if fa > fb { @@ -468,7 +468,7 @@ enum Month { } /// Parse the beginning string into a Month, returning Month::Unknown on errors. -fn month_parse(line: &String) -> Month { +fn month_parse(line: &str) -> Month { match line.split_whitespace() .next() .unwrap() @@ -491,11 +491,11 @@ fn month_parse(line: &String) -> Month { } } -fn month_compare(a: &String, b: &String) -> Ordering { +fn month_compare(a: &str, b: &str) -> Ordering { month_parse(a).cmp(&month_parse(b)) } -fn version_compare(a: &String, b: &String) -> Ordering { +fn version_compare(a: &str, b: &str) -> Ordering { let ver_a = Version::parse(a); let ver_b = Version::parse(b); if ver_a > ver_b { diff --git a/src/tsort/tsort.rs b/src/tsort/tsort.rs index dc1dd7192..b24ce5007 100644 --- a/src/tsort/tsort.rs +++ b/src/tsort/tsort.rs @@ -135,12 +135,12 @@ impl Graph { self.in_edges.get(to).unwrap().contains(from) } - fn init_node(&mut self, n: &String) { - self.in_edges.insert(n.clone(), HashSet::new()); - self.out_edges.insert(n.clone(), vec![]); + fn init_node(&mut self, n: &str) { + self.in_edges.insert(n.to_string(), HashSet::new()); + self.out_edges.insert(n.to_string(), vec![]); } - fn add_edge(&mut self, from: &String, to: &String) { + fn add_edge(&mut self, from: &str, to: &str) { if !self.has_node(to) { self.init_node(to); } @@ -150,8 +150,8 @@ impl Graph { } if from != to && !self.has_edge(from, to) { - self.in_edges.get_mut(to).unwrap().insert(from.clone()); - self.out_edges.get_mut(from).unwrap().push(to.clone()); + self.in_edges.get_mut(to).unwrap().insert(from.to_string()); + self.out_edges.get_mut(from).unwrap().push(to.to_string()); } }