make clippy happy

This commit is contained in:
zonyitoo
2021-05-07 11:55:16 +08:00
parent e8fd2c6a9d
commit 032aba58fa
3 changed files with 7 additions and 7 deletions
+4 -4
View File
@@ -1233,12 +1233,12 @@ impl Config {
if svr.tcp_weight.is_some() || svr.udp_weight.is_some() {
let tcp_weight = svr.tcp_weight.unwrap_or(1.0);
if tcp_weight < 0.0 || tcp_weight > 1.0 {
if !(0.0..=1.0).contains(&tcp_weight) {
let err = Error::new(ErrorKind::Invalid, "invalid `tcp_weight`, must be in [0, 1]", None);
return Err(err);
}
let udp_weight = svr.udp_weight.unwrap_or(1.0);
if udp_weight < 0.0 || udp_weight > 1.0 {
if !(0.0..=1.0).contains(&udp_weight) {
let err = Error::new(ErrorKind::Invalid, "invalid `udp_weight`, must be in [0, 1]", None);
return Err(err);
}
@@ -1753,12 +1753,12 @@ impl fmt::Display for Config {
remarks: svr.remarks().map(ToOwned::to_owned),
id: svr.id().map(ToOwned::to_owned),
mode: Some(svr.mode().to_string()),
tcp_weight: if svr.weight().tcp_weight() != 1.0 {
tcp_weight: if (svr.weight().tcp_weight() - 1.0).abs() > f32::EPSILON {
Some(svr.weight().tcp_weight())
} else {
None
},
udp_weight: if svr.weight().udp_weight() != 1.0 {
udp_weight: if (svr.weight().udp_weight() - 1.0).abs() > f32::EPSILON {
Some(svr.weight().udp_weight())
} else {
None
@@ -50,7 +50,7 @@ fn max_latency_stdev() -> f64 {
impl ServerStat {
pub fn new(user_weight: f32) -> ServerStat {
assert!(user_weight >= 0.0 && user_weight <= 1.0);
assert!((0.0..=1.0).contains(&user_weight));
ServerStat {
rtt: MAX_SERVER_RTT,
+2 -2
View File
@@ -128,7 +128,7 @@ impl ServerWeight {
/// Set weight for TCP balancer in `[0, 1]`
pub fn set_tcp_weight(&mut self, weight: f32) {
assert!(weight >= 0.0 && weight <= 1.0);
assert!((0.0..=1.0).contains(&weight));
self.tcp_weight = weight;
}
@@ -139,7 +139,7 @@ impl ServerWeight {
/// Set weight for UDP balancer in `[0, 1]`
pub fn set_udp_weight(&mut self, weight: f32) {
assert!(weight >= 0.0 && weight <= 1.0);
assert!((0.0..=1.0).contains(&weight));
self.udp_weight = weight;
}
}