Resolve clippy suggestions

This commit is contained in:
timvisee 2021-11-11 13:37:06 +01:00
parent e6e2e7fab8
commit 51ab0c610b
No known key found for this signature in database
GPG Key ID: B8DB720BC383E172
12 changed files with 30 additions and 33 deletions

View File

@ -15,16 +15,16 @@ pub fn invoke(matches: &ArgMatches) {
}
// Confirm to overwrite if it exists
if path.is_file() {
if !prompt_yes(
if path.is_file()
&& !prompt_yes(
&format!(
"Config file already exists, overwrite?\nPath: {}",
path.to_str().unwrap_or("?")
),
Some(true),
) {
quit();
}
)
{
quit();
}
// Generate file

View File

@ -53,17 +53,17 @@ fn init_log() {
}
/// Invoke an action.
fn invoke_action<'a>(app: App<'a>) -> Result<(), ()> {
fn invoke_action(app: App) -> Result<(), ()> {
let matches = app.get_matches();
// Config operations
if let Some(ref matches) = matches.subcommand_matches("config") {
if let Some(ref matches) = matches.subcommand_matches("generate") {
if let Some(matches) = matches.subcommand_matches("config") {
if let Some(matches) = matches.subcommand_matches("generate") {
action::config_generate::invoke(matches);
return Ok(());
}
if let Some(ref matches) = matches.subcommand_matches("test") {
if let Some(matches) = matches.subcommand_matches("test") {
action::config_test::invoke(matches);
return Ok(());
}

View File

@ -87,7 +87,6 @@ pub fn rewrite_file(file: &Path, changes: HashMap<&str, String>) {
FILE,
err,
);
return;
}
};
}
@ -110,7 +109,7 @@ fn rewrite_contents(contents: String, mut changes: HashMap<&str, String>) -> Opt
// Skip comments or empty lines
let trim = line.trim();
if trim.starts_with("#") || trim.is_empty() {
if trim.starts_with('#') || trim.is_empty() {
return line;
}

View File

@ -98,7 +98,7 @@ pub async fn poll_server(
async fn fetch_status(config: &Config, addr: SocketAddr) -> Result<ServerStatus, ()> {
let mut stream = TcpStream::connect(addr).await.map_err(|_| ())?;
send_handshake(&mut stream, &config, addr).await?;
send_handshake(&mut stream, config, addr).await?;
request_status(&mut stream).await?;
wait_for_status_timeout(&mut stream).await
}
@ -107,7 +107,7 @@ async fn fetch_status(config: &Config, addr: SocketAddr) -> Result<ServerStatus,
async fn do_ping(config: &Config, addr: SocketAddr) -> Result<(), ()> {
let mut stream = TcpStream::connect(addr).await.map_err(|_| ())?;
send_handshake(&mut stream, &config, addr).await?;
send_handshake(&mut stream, config, addr).await?;
let token = send_ping(&mut stream).await?;
wait_for_ping_timeout(&mut stream, token).await
}

View File

@ -133,7 +133,7 @@ impl RawPacket {
let mut packet = types::encode_var_int(len)?;
packet.append(&mut data);
return Ok(packet);
Ok(packet)
}
}
@ -142,9 +142,9 @@ impl RawPacket {
/// Note: this does not support reading compressed/encrypted packets.
/// We should never need this though, as we're done reading user packets before any of this is
/// enabled. See: https://wiki.vg/Protocol#Packet_format
pub async fn read_packet<'a>(
pub async fn read_packet(
buf: &mut BytesMut,
stream: &mut ReadHalf<'a>,
stream: &mut ReadHalf<'_>,
) -> Result<Option<(RawPacket, Vec<u8>)>, ()> {
// Keep reading until we have at least 2 bytes
while buf.len() < 2 {
@ -166,7 +166,7 @@ pub async fn read_packet<'a>(
}
// Attempt to read packet length
let (consumed, len) = match types::read_var_int(&buf) {
let (consumed, len) = match types::read_var_int(buf) {
Ok(result) => result,
Err(err) => {
error!(target: "lazymc", "Malformed packet, could not read packet length");

View File

@ -29,7 +29,7 @@ pub async fn proxy_with_queue(
if !queue.is_empty() {
wo.writable().await?;
trace!(target: "lazymc", "Relaying {} queued bytes to server", queue.len());
wo.write_all(&queue).await?;
wo.write_all(queue).await?;
}
let client_to_server = async {

View File

@ -210,13 +210,13 @@ impl Server {
// Try to stop through RCON if started
#[cfg(feature = "rcon")]
if self.state() == State::Started && stop_server_rcon(config, &self).await {
if self.state() == State::Started && stop_server_rcon(config, self).await {
return true;
}
// Try to stop through signal
#[cfg(unix)]
if stop_server_signal(config, &self) {
if stop_server_signal(config, self) {
return true;
}
@ -388,7 +388,7 @@ async fn stop_server_rcon(config: &Config, server: &Server) -> bool {
}
// RCON address
let mut addr = config.server.address.clone();
let mut addr = config.server.address;
addr.set_port(config.rcon.port);
let addr = addr.to_string();

View File

@ -71,7 +71,7 @@ fn route(inbound: TcpStream, config: Arc<Config>, server: Arc<Server>) {
fn route_status(inbound: TcpStream, config: Arc<Config>, server: Arc<Server>) {
// When server is not online, spawn a status server
let client = Client::default();
let service = status::serve(client, inbound, config.clone(), server.clone()).map(|r| {
let service = status::serve(client, inbound, config, server).map(|r| {
if let Err(err) = r {
warn!(target: "lazymc", "Failed to serve status: {:?}", err);
}
@ -95,7 +95,7 @@ fn route_proxy(inbound: TcpStream, config: Arc<Config>) {
/// Route inbound TCP stream to proxy with queued data, spawning a new task.
#[inline]
pub fn route_proxy_queue<'a>(inbound: TcpStream, config: Arc<Config>, queue: BytesMut) {
pub fn route_proxy_queue(inbound: TcpStream, config: Arc<Config>, queue: BytesMut) {
// When server is online, proxy all
let service = async move {
proxy::proxy_with_queue(inbound, config.server.address, &queue)

View File

@ -217,7 +217,7 @@ pub async fn hold<'a>(
/// Kick client with a message.
///
/// Should close connection afterwards.
async fn kick<'a>(msg: &str, writer: &mut WriteHalf<'a>) -> Result<(), ()> {
async fn kick(msg: &str, writer: &mut WriteHalf<'_>) -> Result<(), ()> {
let packet = LoginDisconnect {
reason: Message::new(Payload::text(msg)),
};

View File

@ -11,7 +11,7 @@ pub fn read_var_int(buf: &[u8]) -> Result<(usize, i32), ()> {
let buf = &buf[..len];
// Parse var-int, return result
return match minecraft_protocol::decoder::var_int::decode(&mut buf.as_ref()) {
return match minecraft_protocol::decoder::var_int::decode(&mut &*buf) {
Ok(val) => Ok((len, val)),
Err(_) => Err(()),
};

View File

@ -52,8 +52,10 @@ pub fn prompt_yes(msg: &str, def: Option<bool>) -> bool {
let answer = prompt(&format!("{} {}", msg, options));
// Assume the default if the answer is empty
if answer.is_empty() && def.is_some() {
return def.unwrap();
if answer.is_empty() {
if let Some(def) = def {
return def;
}
}
// Derive a boolean and return

View File

@ -30,11 +30,7 @@ pub fn print_error(err: anyhow::Error) {
// Fall back to a basic message
if count == 0 {
eprintln!(
"{} {}",
highlight_error("error:"),
"an undefined error occurred"
);
eprintln!("{} an undefined error occurred", highlight_error("error:"),);
}
}
@ -123,7 +119,7 @@ impl ErrorHints {
return;
}
eprint!("\n");
eprintln!();
// Print hints
let bin = crate::util::bin_name();