Add missing_const_for_fn clippy lint (#8498)

This commit is contained in:
Thomas Coratger
2024-05-30 11:50:03 +02:00
committed by GitHub
parent 99068198db
commit 3d3f52b2a4
255 changed files with 834 additions and 804 deletions

View File

@ -6,7 +6,7 @@ use std::{collections::HashMap, net::IpAddr, time::Instant};
/// Determines whether or not the IP is globally routable.
/// Should be replaced with [`IpAddr::is_global`](std::net::IpAddr::is_global) once it is stable.
pub fn is_global(ip: &IpAddr) -> bool {
pub const fn is_global(ip: &IpAddr) -> bool {
if ip.is_unspecified() || ip.is_loopback() {
return false
}
@ -40,7 +40,7 @@ impl BanList {
}
/// Creates a new ban list that bans the given peers and ips with an optional timeout.
pub fn new_with_timeout(
pub const fn new_with_timeout(
banned_peers: HashMap<PeerId, Option<Instant>>,
banned_ips: HashMap<IpAddr, Option<Instant>>,
) -> Self {

View File

@ -104,17 +104,17 @@ impl<S> MeteredStream<S> {
/// Creates a new [`MeteredStream`] wrapping around the provided stream,
/// attaching the provided [`BandwidthMeter`]
pub fn new_with_meter(inner: S, meter: BandwidthMeter) -> Self {
pub const fn new_with_meter(inner: S, meter: BandwidthMeter) -> Self {
Self { inner, meter }
}
/// Provides a reference to the [`BandwidthMeter`] attached to this [`MeteredStream`]
pub fn get_bandwidth_meter(&self) -> &BandwidthMeter {
pub const fn get_bandwidth_meter(&self) -> &BandwidthMeter {
&self.meter
}
/// Returns the wrapped stream
pub fn inner(&self) -> &S {
pub const fn inner(&self) -> &S {
&self.inner
}
}

View File

@ -28,7 +28,7 @@ impl RateLimit {
}
/// Returns the configured limit of the [RateLimit]
pub fn limit(&self) -> u64 {
pub const fn limit(&self) -> u64 {
self.rate.limit()
}
@ -106,15 +106,15 @@ pub struct Rate {
impl Rate {
/// Create a new [Rate] with the given `limit/duration` ratio.
pub fn new(limit: u64, duration: Duration) -> Self {
pub const fn new(limit: u64, duration: Duration) -> Self {
Self { limit, duration }
}
fn limit(&self) -> u64 {
const fn limit(&self) -> u64 {
self.limit
}
fn duration(&self) -> Duration {
const fn duration(&self) -> Duration {
self.duration
}
}