Fix: clippy warning in rust 1.66.0

This commit is contained in:
Bo Zhang
2022-08-02 15:52:01 +08:00
committed by dlhxzb
parent d7b2060a5b
commit 60a6d672c5
18 changed files with 355 additions and 409 deletions

View File

@@ -12,15 +12,17 @@ use std::{
time::{Instant, SystemTime},
};
#[allow(dead_code)]
pub(crate) fn get_expired_time() -> Instant {
let now = Instant::now();
now.checked_sub(std::time::Duration::from_secs(3600))
.unwrap_or(now)
}
#[allow(dead_code)]
pub(crate) fn test_if_valid_server(host: &str, name: &str) -> ResultType<SocketAddr> {
use std::net::ToSocketAddrs;
let res = if host.contains(":") {
let res = if host.contains(':') {
host.to_socket_addrs()?.next().context("")
} else {
format!("{}:{}", host, 0)
@@ -34,9 +36,10 @@ pub(crate) fn test_if_valid_server(host: &str, name: &str) -> ResultType<SocketA
res
}
#[allow(dead_code)]
pub(crate) fn get_servers(s: &str, tag: &str) -> Vec<String> {
let servers: Vec<String> = s
.split(",")
.split(',')
.filter(|x| !x.is_empty() && test_if_valid_server(x, tag).is_ok())
.map(|x| x.to_owned())
.collect();
@@ -44,17 +47,19 @@ pub(crate) fn get_servers(s: &str, tag: &str) -> Vec<String> {
servers
}
#[allow(dead_code)]
#[inline]
fn arg_name(name: &str) -> String {
name.to_uppercase().replace("_", "-")
name.to_uppercase().replace('_', "-")
}
#[allow(dead_code)]
pub fn init_args(args: &str, name: &str, about: &str) {
let matches = App::new(name)
.version(crate::version::VERSION)
.author("Purslane Ltd. <info@rustdesk.com>")
.about(about)
.args_from_usage(&args)
.args_from_usage(args)
.get_matches();
if let Ok(v) = Ini::load_from_file(".env") {
if let Some(section) = v.section(None::<String>) {
@@ -79,16 +84,19 @@ pub fn init_args(args: &str, name: &str, about: &str) {
}
}
#[allow(dead_code)]
#[inline]
pub fn get_arg(name: &str) -> String {
get_arg_or(name, "".to_owned())
}
#[allow(dead_code)]
#[inline]
pub fn get_arg_or(name: &str, default: String) -> String {
std::env::var(arg_name(name)).unwrap_or(default)
}
#[allow(dead_code)]
#[inline]
pub fn now() -> u64 {
SystemTime::now()
@@ -121,7 +129,7 @@ pub fn gen_sk(wait: u64) -> (String, Option<sign::SecretKey>) {
};
let (mut pk, mut sk) = gen_func();
for _ in 0..300 {
if !pk.contains("/") && !pk.contains(":") {
if !pk.contains('/') && !pk.contains(':') {
break;
}
(pk, sk) = gen_func();