From d43b588e5160f416c62065391818fa8a5104e295 Mon Sep 17 00:00:00 2001 From: Raptorox <70806316+Raptorox@users.noreply.github.com> Date: Sat, 1 Aug 2026 19:17:08 +0200 Subject: [PATCH] lint --- src/client/mod.rs | 34 ++++++++++++++++++++++++---------- src/client/packet_type.rs | 6 +++--- src/command/ban.rs | 24 ++++++++++++++++-------- src/command/banlist.rs | 17 +++++++++-------- src/command/defaultgamemode.rs | 14 ++++++++------ src/command/deop.rs | 14 ++++++++------ src/command/difficulty.rs | 10 ++++++---- src/command/gamemode.rs | 16 +++++++++------- src/command/kill.rs | 14 ++++++++------ src/command/list.rs | 18 ++++++++++-------- src/command/op.rs | 14 ++++++++------ src/command/say.rs | 12 +++++++----- 12 files changed, 116 insertions(+), 77 deletions(-) diff --git a/src/client/mod.rs b/src/client/mod.rs index 207c979..46f1ec2 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -1,4 +1,8 @@ -use std::{fmt::Display, io::{self, Read, Write}, net::{TcpStream, ToSocketAddrs}}; +use std::{ + fmt::Display, + io::{self, Read, Write}, + net::{TcpStream, ToSocketAddrs}, +}; mod packet_type; use packet_type::PacketType; @@ -6,7 +10,7 @@ use packet_type::PacketType; pub enum RconError { Io(io::Error), AuthFailed, - InvalidResponse(String) + InvalidResponse(String), } pub type RconResult = Result; @@ -15,7 +19,7 @@ impl Display for RconError { match self { RconError::Io(e) => write!(f, "io error: {e}"), RconError::AuthFailed => write!(f, "auth failed"), - RconError::InvalidResponse(e) => write!(f, "invalid response from server: {e}") + RconError::InvalidResponse(e) => write!(f, "invalid response from server: {e}"), } } } @@ -28,7 +32,7 @@ impl From for RconError { pub struct RconClient { stream: TcpStream, - next_id: i32 + next_id: i32, } impl RconClient { @@ -41,13 +45,19 @@ impl RconClient { fn recv_packet(&mut self) -> RconResult<(i32, PacketType, String)> { let length = self.read_i32_le()?; if length < 10 { - return Err(RconError::InvalidResponse("response length < 10".to_string())) + return Err(RconError::InvalidResponse( + "response length < 10".to_string(), + )); } let id = self.read_i32_le()?; let ptype = match PacketType::try_from(self.read_i32_le()?) { Ok(ptype) => ptype, - Err(()) => return Err(RconError::InvalidResponse("unknown packet type".to_string())) + Err(()) => { + return Err(RconError::InvalidResponse( + "unknown packet type".to_string(), + )); + } }; let payload_len = (length - 10) as usize; @@ -91,7 +101,7 @@ impl RconClient { Ok(()) } - + pub fn connect(addr: impl ToSocketAddrs, password: &str) -> RconResult { let stream = TcpStream::connect(addr)?; let mut client = RconClient { stream, next_id: 1 }; @@ -104,12 +114,16 @@ impl RconClient { let (resp_id, resp_type, payload) = self.recv_packet()?; if resp_type != PacketType::Response { - return Err(RconError::InvalidResponse("received packet not of response type".to_string())) + return Err(RconError::InvalidResponse( + "received packet not of response type".to_string(), + )); } if resp_id != id { - return Err(RconError::InvalidResponse("mismatched packet id".to_string())) + return Err(RconError::InvalidResponse( + "mismatched packet id".to_string(), + )); } Ok(payload) } -} \ No newline at end of file +} diff --git a/src/client/packet_type.rs b/src/client/packet_type.rs index bc4e0ed..5834a59 100644 --- a/src/client/packet_type.rs +++ b/src/client/packet_type.rs @@ -2,7 +2,7 @@ pub enum PacketType { Login = 3, Command = 2, - Response = 0 + Response = 0, } impl PacketType { @@ -19,7 +19,7 @@ impl TryFrom for PacketType { x if x == Self::Login as i32 => Ok(Self::Login), x if x == Self::Command as i32 => Ok(Self::Command), x if x == Self::Response as i32 => Ok(Self::Response), - _ => Err(()) + _ => Err(()), } } -} \ No newline at end of file +} diff --git a/src/command/ban.rs b/src/command/ban.rs index 9c27b3f..8783e2b 100644 --- a/src/command/ban.rs +++ b/src/command/ban.rs @@ -1,12 +1,14 @@ +use super::{Command, Selector}; + #[derive(Default)] pub struct BanCommand { - target: Option, + target: Option, reason: Option, - ip: Option + ip: Option, } impl BanCommand { - pub fn target(mut self, target: super::Selector) -> Self { + pub fn target(mut self, target: Selector) -> Self { self.target = Some(target); self } @@ -21,13 +23,19 @@ impl BanCommand { self } - pub fn build(self) -> super::Command { - let target = self.target.unwrap_or(super::Selector::Player("nonexistent".to_string())); + pub fn build(self) -> Command { + let target = self + .target + .unwrap_or(Selector::Player("nonexistent".to_string())); let ip = self.ip.unwrap_or(false); - let mut s = if ip { format!("ban-ip {target}") } else { format!("ban {target}") }; + let mut s = if ip { + format!("ban-ip {target}") + } else { + format!("ban {target}") + }; if let Some(reason) = self.reason { s.push_str(&format!(" {reason}")); }; - super::Command(s) + Command(s) } -} \ No newline at end of file +} diff --git a/src/command/banlist.rs b/src/command/banlist.rs index dd227e5..8ceba79 100644 --- a/src/command/banlist.rs +++ b/src/command/banlist.rs @@ -1,8 +1,9 @@ +use super::Command; use std::marker::PhantomData; #[derive(Default)] pub struct BanlistCommand { - state: PhantomData + state: PhantomData, } pub struct NoFilter; @@ -22,19 +23,19 @@ impl BanlistCommand { BanlistCommand { state: PhantomData } } - pub fn build(self) -> super::Command { - super::Command::raw("banlist") + pub fn build(self) -> Command { + Command::raw("banlist") } } impl BanlistCommand { - pub fn build(self) -> super::Command { - super::Command::raw("banlist players") + pub fn build(self) -> Command { + Command::raw("banlist players") } } impl BanlistCommand { - pub fn build(self) -> super::Command { - super::Command::raw("banlist ips") + pub fn build(self) -> Command { + Command::raw("banlist ips") } -} \ No newline at end of file +} diff --git a/src/command/defaultgamemode.rs b/src/command/defaultgamemode.rs index 324df9d..6d2183c 100644 --- a/src/command/defaultgamemode.rs +++ b/src/command/defaultgamemode.rs @@ -1,17 +1,19 @@ +use super::{Command, Gamemode}; + #[derive(Default)] pub struct DefaultGamemodeCommand { - gamemode: Option + gamemode: Option, } impl DefaultGamemodeCommand { - pub fn gamemode(mut self, gamemode: super::Gamemode) -> Self { + pub fn gamemode(mut self, gamemode: Gamemode) -> Self { self.gamemode = Some(gamemode); self } - pub fn build(self) -> super::Command { - let gamemode = self.gamemode.unwrap_or(super::Gamemode::Survival); + pub fn build(self) -> Command { + let gamemode = self.gamemode.unwrap_or(Gamemode::Survival); let s = format!("defaultgamemode {gamemode}"); - super::Command(s) + Command(s) } -} \ No newline at end of file +} diff --git a/src/command/deop.rs b/src/command/deop.rs index 5f4eda3..05832dd 100644 --- a/src/command/deop.rs +++ b/src/command/deop.rs @@ -1,17 +1,19 @@ +use super::{Command, Selector}; + #[derive(Default)] pub struct DeopCommand { - target: Option + target: Option, } impl DeopCommand { - pub fn target(mut self, target: super::Selector) -> Self { + pub fn target(mut self, target: Selector) -> Self { self.target = Some(target); self } - pub fn build(self) -> super::Command { - let target = self.target.unwrap_or(super::Selector::Executor); + pub fn build(self) -> Command { + let target = self.target.unwrap_or(Selector::Executor); let s = format!("deop {target}"); - super::Command(s) + Command(s) } -} \ No newline at end of file +} diff --git a/src/command/difficulty.rs b/src/command/difficulty.rs index 9a663c8..4c01e6f 100644 --- a/src/command/difficulty.rs +++ b/src/command/difficulty.rs @@ -1,19 +1,21 @@ +use super::{Command, Difficulty}; + #[derive(Default)] pub struct DifficultyCommand { - difficulty: Option + difficulty: Option } impl DifficultyCommand { - pub fn difficulty(mut self, difficulty: super::Difficulty) -> Self { + pub fn difficulty(mut self, difficulty: Difficulty) -> Self { self.difficulty = Some(difficulty); self } - pub fn build(self) -> super::Command { + pub fn build(self) -> Command { let mut s = format!("difficulty"); if let Some(difficulty) = self.difficulty { s.push_str(&format!(" {difficulty}")) }; - super::Command(s) + Command(s) } } \ No newline at end of file diff --git a/src/command/gamemode.rs b/src/command/gamemode.rs index d6759ae..9a6b5d9 100644 --- a/src/command/gamemode.rs +++ b/src/command/gamemode.rs @@ -1,26 +1,28 @@ +use super::{Command, Gamemode, Selector}; + #[derive(Default)] pub struct GamemodeCommand { - gamemode: Option, - target: Option + gamemode: Option, + target: Option } impl GamemodeCommand { - pub fn gamemode(mut self, gamemode: super::Gamemode) -> Self { + pub fn gamemode(mut self, gamemode: Gamemode) -> Self { self.gamemode = Some(gamemode); self } - pub fn target(mut self, target: super::Selector) -> Self { + pub fn target(mut self, target: Selector) -> Self { self.target = Some(target); self } - pub fn build(self) -> super::Command { - let gamemode = self.gamemode.unwrap_or(super::Gamemode::Survival); + pub fn build(self) -> Command { + let gamemode = self.gamemode.unwrap_or(Gamemode::Survival); let mut s = format!("defaultgamemode {gamemode}"); if let Some(target) = self.target { s.push_str(&format!(" {target}")) } - super::Command(s) + Command(s) } } \ No newline at end of file diff --git a/src/command/kill.rs b/src/command/kill.rs index bc8b1a2..d365fbb 100644 --- a/src/command/kill.rs +++ b/src/command/kill.rs @@ -1,17 +1,19 @@ +use super::{Command, Selector}; + #[derive(Default)] pub struct KillCommand { - target: Option + target: Option, } impl KillCommand { - pub fn target(mut self, target: super::Selector) -> Self { + pub fn target(mut self, target: Selector) -> Self { self.target = Some(target); self } - pub fn build(self) -> super::Command { - let target = self.target.unwrap_or(super::Selector::Executor); + pub fn build(self) -> Command { + let target = self.target.unwrap_or(Selector::Executor); let s = format!("kill {target}"); - super::Command(s) + Command(s) } -} \ No newline at end of file +} diff --git a/src/command/list.rs b/src/command/list.rs index fc42328..398bdec 100644 --- a/src/command/list.rs +++ b/src/command/list.rs @@ -1,17 +1,19 @@ +use super::Command; + #[derive(Default)] pub struct ListCommand { - uuids: Option + uuids: Option, } impl ListCommand { pub fn uuids(mut self) -> Self { self.uuids = Some(true); self - } - - pub fn build(self) -> super::Command { - let uuids = self.uuids.unwrap_or(false); - let s = format!("list {}", if uuids { "uuids" } else {""} ); - super::Command(s) } -} \ No newline at end of file + + pub fn build(self) -> Command { + let uuids = self.uuids.unwrap_or(false); + let s = format!("list {}", if uuids { "uuids" } else { "" }); + Command(s) + } +} diff --git a/src/command/op.rs b/src/command/op.rs index af05c56..28e3cc2 100644 --- a/src/command/op.rs +++ b/src/command/op.rs @@ -1,17 +1,19 @@ +use super::{Command, Selector}; + #[derive(Default)] pub struct OpCommand { - target: Option + target: Option, } impl OpCommand { - pub fn target(mut self, target: super::Selector) -> Self { + pub fn target(mut self, target: Selector) -> Self { self.target = Some(target); self } - pub fn build(self) -> super::Command { - let target = self.target.unwrap_or(super::Selector::Executor); + pub fn build(self) -> Command { + let target = self.target.unwrap_or(Selector::Executor); let s = format!("op {target}"); - super::Command(s) + Command(s) } -} \ No newline at end of file +} diff --git a/src/command/say.rs b/src/command/say.rs index 6f92b75..44e5fe5 100644 --- a/src/command/say.rs +++ b/src/command/say.rs @@ -1,17 +1,19 @@ +use super::Command; + #[derive(Default)] pub struct SayCommand { - message: Option + message: Option, } impl SayCommand { pub fn message(mut self, msg: impl Into) -> Self { self.message = Some(msg.into()); self - } + } - pub fn build(self) -> super::Command { + pub fn build(self) -> Command { let message = self.message.unwrap_or("Hello, world!".to_string()); let s = format!("say {message}"); - super::Command(s) + Command(s) } -} \ No newline at end of file +}