1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-08-04 15:07:47 +00:00

refactor/polish ~ fix cargo clippy complaints (unneeded ref for copiable)

This commit is contained in:
Roy Ivy III 2019-12-26 15:41:47 -06:00
parent bc558f301a
commit 1216378c72
4 changed files with 20 additions and 20 deletions

View file

@ -17,7 +17,7 @@ pub fn err_msg(msg: &str) {
// by default stdout only flushes // by default stdout only flushes
// to console when a newline is passed. // to console when a newline is passed.
#[allow(unused_must_use)] #[allow(unused_must_use)]
pub fn flush_char(c: &char) { pub fn flush_char(c: char) {
print!("{}", c); print!("{}", c);
stdout().flush(); stdout().flush();
} }

View file

@ -190,7 +190,7 @@ impl UnescapedText {
// lazy branch eval // lazy branch eval
// remember this fn could be called // remember this fn could be called
// many times in a single exec through %b // many times in a single exec through %b
cli::flush_char(&ch); cli::flush_char(ch);
tmp_str.push(ch); tmp_str.push(ch);
} }
'\\' => { '\\' => {
@ -210,7 +210,7 @@ impl UnescapedText {
x if x == '%' && !subs_mode => { x if x == '%' && !subs_mode => {
if let Some(follow) = it.next() { if let Some(follow) = it.next() {
if follow == '%' { if follow == '%' {
cli::flush_char(&ch); cli::flush_char(ch);
tmp_str.push(ch); tmp_str.push(ch);
} else { } else {
it.put_back(follow); it.put_back(follow);
@ -223,7 +223,7 @@ impl UnescapedText {
} }
} }
_ => { _ => {
cli::flush_char(&ch); cli::flush_char(ch);
tmp_str.push(ch); tmp_str.push(ch);
} }
} }

View file

@ -560,8 +560,8 @@ fn is_seekable<T: Seek>(file: &mut T) -> bool {
} }
#[inline] #[inline]
fn print_byte<T: Write>(stdout: &mut T, ch: &u8) { fn print_byte<T: Write>(stdout: &mut T, ch: u8) {
if let Err(err) = stdout.write(&[*ch]) { if let Err(err) = stdout.write(&[ch]) {
crash!(1, "{}", err); crash!(1, "{}", err);
} }
} }

View file

@ -33,7 +33,7 @@ static VERSION: &str = env!("CARGO_PKG_VERSION");
const BUFFER_LEN: usize = 1024; const BUFFER_LEN: usize = 1024;
trait SymbolTranslator { trait SymbolTranslator {
fn translate(&self, c: &char, prev_c: &char) -> Option<char>; fn translate(&self, c: char, prev_c: char) -> Option<char>;
} }
struct DeleteOperation { struct DeleteOperation {
@ -51,10 +51,10 @@ impl DeleteOperation {
} }
impl SymbolTranslator for DeleteOperation { impl SymbolTranslator for DeleteOperation {
fn translate(&self, c: &char, _prev_c: &char) -> Option<char> { fn translate(&self, c: char, _prev_c: char) -> Option<char> {
let uc = *c as usize; let uc = c as usize;
if self.complement == self.bset.contains(uc) { if self.complement == self.bset.contains(uc) {
Some(*c) Some(c)
} else { } else {
None None
} }
@ -76,11 +76,11 @@ impl SqueezeOperation {
} }
impl SymbolTranslator for SqueezeOperation { impl SymbolTranslator for SqueezeOperation {
fn translate(&self, c: &char, prev_c: &char) -> Option<char> { fn translate(&self, c: char, prev_c: char) -> Option<char> {
if *prev_c == *c && self.complement != self.squeeze_set.contains(*c as usize) { if prev_c == c && self.complement != self.squeeze_set.contains(c as usize) {
None None
} else { } else {
Some(*c) Some(c)
} }
} }
} }
@ -106,13 +106,13 @@ impl DeleteAndSqueezeOperation {
} }
impl SymbolTranslator for DeleteAndSqueezeOperation { impl SymbolTranslator for DeleteAndSqueezeOperation {
fn translate(&self, c: &char, prev_c: &char) -> Option<char> { fn translate(&self, c: char, prev_c: char) -> Option<char> {
if self.complement != self.delete_set.contains(*c as usize) if self.complement != self.delete_set.contains(c as usize)
|| *prev_c == *c && self.squeeze_set.contains(*c as usize) || prev_c == c && self.squeeze_set.contains(c as usize)
{ {
None None
} else { } else {
Some(*c) Some(c)
} }
} }
} }
@ -140,8 +140,8 @@ impl TranslateOperation {
} }
impl SymbolTranslator for TranslateOperation { impl SymbolTranslator for TranslateOperation {
fn translate(&self, c: &char, _prev_c: &char) -> Option<char> { fn translate(&self, c: char, _prev_c: char) -> Option<char> {
Some(*self.translate_map.get(&(*c as usize)).unwrap_or(c)) Some(*self.translate_map.get(&(c as usize)).unwrap_or(&c))
} }
} }
@ -161,7 +161,7 @@ fn translate_input<T: SymbolTranslator>(
{ {
// isolation to make borrow checker happy // isolation to make borrow checker happy
let filtered = buf.chars().filter_map(|c| { let filtered = buf.chars().filter_map(|c| {
let res = translator.translate(&c, &prev_c); let res = translator.translate(c, prev_c);
if res.is_some() { if res.is_some() {
prev_c = c; prev_c = c;
} }