mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-04-30 03:01:58 -04:00
Add missing_const_for_fn clippy lint (#8498)
This commit is contained in:
@@ -685,7 +685,7 @@ impl InflightRequest {
|
||||
|
||||
/// Returns true if we're still waiting for a response
|
||||
#[inline]
|
||||
fn is_waiting(&self) -> bool {
|
||||
const fn is_waiting(&self) -> bool {
|
||||
matches!(self.request, RequestState::Waiting(_))
|
||||
}
|
||||
|
||||
|
||||
@@ -82,7 +82,7 @@ impl SessionsConfig {
|
||||
///
|
||||
/// It is expected, that the background session task will stall if they outpace the manager. The
|
||||
/// buffer size provides backpressure on the network I/O.
|
||||
pub fn with_session_event_buffer(mut self, n: usize) -> Self {
|
||||
pub const fn with_session_event_buffer(mut self, n: usize) -> Self {
|
||||
self.session_event_buffer = n;
|
||||
self
|
||||
}
|
||||
@@ -119,25 +119,25 @@ pub struct SessionLimits {
|
||||
|
||||
impl SessionLimits {
|
||||
/// Sets the maximum number of pending incoming sessions.
|
||||
pub fn with_max_pending_inbound(mut self, limit: u32) -> Self {
|
||||
pub const fn with_max_pending_inbound(mut self, limit: u32) -> Self {
|
||||
self.max_pending_inbound = Some(limit);
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the maximum number of pending outbound sessions.
|
||||
pub fn with_max_pending_outbound(mut self, limit: u32) -> Self {
|
||||
pub const fn with_max_pending_outbound(mut self, limit: u32) -> Self {
|
||||
self.max_pending_outbound = Some(limit);
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the maximum number of active inbound sessions.
|
||||
pub fn with_max_established_inbound(mut self, limit: u32) -> Self {
|
||||
pub const fn with_max_established_inbound(mut self, limit: u32) -> Self {
|
||||
self.max_established_inbound = Some(limit);
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the maximum number of active outbound sessions.
|
||||
pub fn with_max_established_outbound(mut self, limit: u32) -> Self {
|
||||
pub const fn with_max_established_outbound(mut self, limit: u32) -> Self {
|
||||
self.max_established_outbound = Some(limit);
|
||||
self
|
||||
}
|
||||
@@ -161,7 +161,7 @@ pub struct SessionCounter {
|
||||
// === impl SessionCounter ===
|
||||
|
||||
impl SessionCounter {
|
||||
pub(crate) fn new(limits: SessionLimits) -> Self {
|
||||
pub(crate) const fn new(limits: SessionLimits) -> Self {
|
||||
Self {
|
||||
limits,
|
||||
pending_inbound: 0,
|
||||
@@ -212,15 +212,15 @@ impl SessionCounter {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn ensure_pending_outbound(&self) -> Result<(), ExceedsSessionLimit> {
|
||||
pub(crate) const fn ensure_pending_outbound(&self) -> Result<(), ExceedsSessionLimit> {
|
||||
Self::ensure(self.pending_outbound, self.limits.max_pending_outbound)
|
||||
}
|
||||
|
||||
pub(crate) fn ensure_pending_inbound(&self) -> Result<(), ExceedsSessionLimit> {
|
||||
pub(crate) const fn ensure_pending_inbound(&self) -> Result<(), ExceedsSessionLimit> {
|
||||
Self::ensure(self.pending_inbound, self.limits.max_pending_inbound)
|
||||
}
|
||||
|
||||
fn ensure(current: u32, limit: Option<u32>) -> Result<(), ExceedsSessionLimit> {
|
||||
const fn ensure(current: u32, limit: Option<u32>) -> Result<(), ExceedsSessionLimit> {
|
||||
if let Some(limit) = limit {
|
||||
if current >= limit {
|
||||
return Err(ExceedsSessionLimit(limit))
|
||||
|
||||
@@ -38,7 +38,7 @@ pub enum EthRlpxConnection {
|
||||
impl EthRlpxConnection {
|
||||
/// Returns the negotiated ETH version.
|
||||
#[inline]
|
||||
pub(crate) fn version(&self) -> EthVersion {
|
||||
pub(crate) const fn version(&self) -> EthVersion {
|
||||
match self {
|
||||
Self::EthOnly(conn) => conn.version(),
|
||||
Self::Satellite(conn) => conn.primary().version(),
|
||||
@@ -65,7 +65,7 @@ impl EthRlpxConnection {
|
||||
|
||||
/// Returns access to the underlying stream.
|
||||
#[inline]
|
||||
pub(crate) fn inner(&self) -> &P2PStream<ECIESStream<MeteredStream<TcpStream>>> {
|
||||
pub(crate) const fn inner(&self) -> &P2PStream<ECIESStream<MeteredStream<TcpStream>>> {
|
||||
match self {
|
||||
Self::EthOnly(conn) => conn.inner(),
|
||||
Self::Satellite(conn) => conn.inner(),
|
||||
@@ -142,14 +142,14 @@ impl Sink<EthMessage> for EthRlpxConnection {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
fn assert_eth_stream<St>()
|
||||
const fn assert_eth_stream<St>()
|
||||
where
|
||||
St: Stream<Item = Result<EthMessage, EthStreamError>> + Sink<EthMessage>,
|
||||
{
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_eth_stream_variants() {
|
||||
const fn test_eth_stream_variants() {
|
||||
assert_eth_stream::<EthSatelliteConnection>();
|
||||
assert_eth_stream::<EthRlpxConnection>();
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ impl PendingSessionHandle {
|
||||
}
|
||||
|
||||
/// Returns the direction of the pending session (inbound or outbound).
|
||||
pub fn direction(&self) -> Direction {
|
||||
pub const fn direction(&self) -> Direction {
|
||||
self.direction
|
||||
}
|
||||
}
|
||||
@@ -96,27 +96,27 @@ impl ActiveSessionHandle {
|
||||
}
|
||||
|
||||
/// Returns the direction of the active session (inbound or outbound).
|
||||
pub fn direction(&self) -> Direction {
|
||||
pub const fn direction(&self) -> Direction {
|
||||
self.direction
|
||||
}
|
||||
|
||||
/// Returns the assigned session id for this session.
|
||||
pub fn session_id(&self) -> SessionId {
|
||||
pub const fn session_id(&self) -> SessionId {
|
||||
self.session_id
|
||||
}
|
||||
|
||||
/// Returns the negotiated eth version for this session.
|
||||
pub fn version(&self) -> EthVersion {
|
||||
pub const fn version(&self) -> EthVersion {
|
||||
self.version
|
||||
}
|
||||
|
||||
/// Returns the identifier of the remote peer.
|
||||
pub fn remote_id(&self) -> PeerId {
|
||||
pub const fn remote_id(&self) -> PeerId {
|
||||
self.remote_id
|
||||
}
|
||||
|
||||
/// Returns the timestamp when the session has been established.
|
||||
pub fn established(&self) -> Instant {
|
||||
pub const fn established(&self) -> Instant {
|
||||
self.established
|
||||
}
|
||||
|
||||
@@ -131,7 +131,7 @@ impl ActiveSessionHandle {
|
||||
}
|
||||
|
||||
/// Returns the address we're connected to.
|
||||
pub fn remote_addr(&self) -> SocketAddr {
|
||||
pub const fn remote_addr(&self) -> SocketAddr {
|
||||
self.remote_addr
|
||||
}
|
||||
|
||||
|
||||
@@ -172,12 +172,12 @@ impl SessionManager {
|
||||
}
|
||||
|
||||
/// Returns the current status of the session.
|
||||
pub fn status(&self) -> Status {
|
||||
pub const fn status(&self) -> Status {
|
||||
self.status
|
||||
}
|
||||
|
||||
/// Returns the secret key used for authenticating sessions.
|
||||
pub fn secret_key(&self) -> SecretKey {
|
||||
pub const fn secret_key(&self) -> SecretKey {
|
||||
self.secret_key
|
||||
}
|
||||
|
||||
@@ -753,7 +753,7 @@ pub enum PendingSessionHandshakeError {
|
||||
|
||||
impl PendingSessionHandshakeError {
|
||||
/// Returns the [`DisconnectReason`] if the error is a disconnect message
|
||||
pub fn as_disconnected(&self) -> Option<DisconnectReason> {
|
||||
pub const fn as_disconnected(&self) -> Option<DisconnectReason> {
|
||||
match self {
|
||||
Self::Eth(eth_err) => eth_err.as_disconnected(),
|
||||
_ => None,
|
||||
|
||||
Reference in New Issue
Block a user