mirror of
https://github.com/shadowsocks/shadowsocks-rust.git
synced 2026-11-06 16:14:11 +00:00
make clippy happy
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user