From b0c5f1fe901e6e6abf2775f6fedd668c85494646 Mon Sep 17 00:00:00 2001 From: Hyeon Kim Date: Mon, 15 Nov 2021 03:22:29 +0900 Subject: [PATCH] irc-proto: Fix all trivial clippy warnings using `cargo clippy --fix` --- irc-proto/src/command.rs | 32 ++++++++++++++------------------ irc-proto/src/message.rs | 4 ++-- irc-proto/src/mode.rs | 23 +++++++++-------------- 3 files changed, 25 insertions(+), 34 deletions(-) diff --git a/irc-proto/src/command.rs b/irc-proto/src/command.rs index 669d71f..65f1629 100644 --- a/irc-proto/src/command.rs +++ b/irc-proto/src/command.rs @@ -231,13 +231,13 @@ impl<'a> From<&'a Command> for String { "MODE {}{}", u, m.iter().fold(String::new(), |mut acc, mode| { - acc.push_str(" "); + acc.push(' '); acc.push_str(&mode.to_string()); acc }) ), - Command::SERVICE(ref n, ref r, ref d, ref t, ref re, ref i) => { - stringify("SERVICE", &[n, r, d, t, re, i]) + Command::SERVICE(ref nick, ref r0, ref dist, ref typ, ref r1, ref info) => { + stringify("SERVICE", &[nick, r0, dist, typ, r1, info]) } Command::QUIT(Some(ref m)) => stringify("QUIT", &[m]), Command::QUIT(None) => stringify("QUIT", &[]), @@ -252,7 +252,7 @@ impl<'a> From<&'a Command> for String { "MODE {}{}", u, m.iter().fold(String::new(), |mut acc, mode| { - acc.push_str(" "); + acc.push(' '); acc.push_str(&mode.to_string()); acc }) @@ -445,12 +445,10 @@ impl Command { } else if cmd.eq_ignore_ascii_case("MODE") { if args.is_empty() { raw(cmd, args) + } else if args[0].is_channel_name() { + Command::ChannelMODE(args[0].to_owned(), Mode::as_channel_modes(&args[1..])?) } else { - if args[0].is_channel_name() { - Command::ChannelMODE(args[0].to_owned(), Mode::as_channel_modes(&args[1..])?) - } else { - Command::UserMODE(args[0].to_owned(), Mode::as_user_modes(&args[1..])?) - } + Command::UserMODE(args[0].to_owned(), Mode::as_user_modes(&args[1..])?) } } else if cmd.eq_ignore_ascii_case("SERVICE") { if args.len() != 6 { @@ -665,7 +663,7 @@ impl Command { } else if args.len() == 1 { Command::WHO(Some(args[0].to_owned()), None) } else if args.len() == 2 { - Command::WHO(Some(args[0].to_owned()), Some(&args[1][..] == "o")) + Command::WHO(Some(args[0].to_owned()), Some(args[1] == "o")) } else { raw(cmd, args) } @@ -907,13 +905,12 @@ impl Command { raw(cmd, args) } } else if cmd.eq_ignore_ascii_case("METADATA") { - if args.len() == 2 { - match args[1].parse() { + match args.len() { + 2 => match args[1].parse() { Ok(c) => Command::METADATA(args[0].to_owned(), Some(c), None), Err(_) => raw(cmd, args), - } - } else if args.len() > 2 { - match args[1].parse() { + }, + 3.. => match args[1].parse() { Ok(c) => Command::METADATA( args[0].to_owned(), Some(c), @@ -930,9 +927,8 @@ impl Command { raw(cmd, args) } } - } - } else { - raw(cmd, args) + }, + _ => raw(cmd, args), } } else if cmd.eq_ignore_ascii_case("MONITOR") { if args.len() == 2 { diff --git a/irc-proto/src/message.rs b/irc-proto/src/message.rs index 18dbf41..75c7abc 100644 --- a/irc-proto/src/message.rs +++ b/irc-proto/src/message.rs @@ -58,7 +58,7 @@ impl Message { args: Vec<&str>, ) -> Result { Ok(Message { - tags: tags, + tags, prefix: prefix.map(|p| p.into()), command: Command::new(command, args)?, }) @@ -134,7 +134,7 @@ impl Message { ret.push_str(&tag.0); if let Some(ref value) = tag.1 { ret.push('='); - escape_tag_value(&mut ret, &value); + escape_tag_value(&mut ret, value); } ret.push(';'); } diff --git a/irc-proto/src/mode.rs b/irc-proto/src/mode.rs index 16d1b02..a2044ed 100644 --- a/irc-proto/src/mode.rs +++ b/irc-proto/src/mode.rs @@ -139,11 +139,7 @@ impl ModeType for ChannelMode { fn takes_arg(&self) -> bool { use self::ChannelMode::*; - match *self { - Ban | Exception | Limit | InviteException | Key | Founder | Admin | Oper | Halfop - | Voice => true, - _ => false, - } + matches!(*self, Ban | Exception | Limit | InviteException | Key | Founder | Admin | Oper | Halfop | Voice) } fn from_char(c: char) -> ChannelMode { @@ -234,10 +230,10 @@ where { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { - Mode::Plus(ref mode, Some(ref arg)) => write!(f, "{}{} {}", "+", mode, arg), - Mode::Minus(ref mode, Some(ref arg)) => write!(f, "{}{} {}", "-", mode, arg), - Mode::Plus(ref mode, None) => write!(f, "{}{}", "+", mode), - Mode::Minus(ref mode, None) => write!(f, "{}{}", "-", mode), + Mode::Plus(ref mode, Some(ref arg)) => write!(f, "+{} {}", mode, arg), + Mode::Minus(ref mode, Some(ref arg)) => write!(f, "-{} {}", mode, arg), + Mode::Plus(ref mode, None) => write!(f, "+{}", mode), + Mode::Minus(ref mode, None) => write!(f, "-{}", mode), } } } @@ -282,7 +278,7 @@ where Some('-') => Minus, Some(c) => { return Err(InvalidModeString { - string: pieces.join(" ").to_owned(), + string: pieces.join(" "), cause: InvalidModeModifier { modifier: c }, }) } @@ -313,12 +309,11 @@ where } // TODO: if there are extra args left, this should error - - Ok(res) } else { // No modifier - Ok(res) - } + }; + + Ok(res) } #[cfg(test)]