mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-02-04 20:15:03 -05:00
feat: use FnOnce for node hooks (#7975)
Co-authored-by: Roman Krasiuk <rokrassyuk@gmail.com>
This commit is contained in:
@@ -98,7 +98,7 @@ impl<Node: FullNodeComponents> fmt::Debug for RpcHooks<Node> {
|
||||
pub trait OnRpcStarted<Node: FullNodeComponents>: Send {
|
||||
/// The hook that is called once the rpc server is started.
|
||||
fn on_rpc_started(
|
||||
&self,
|
||||
self: Box<Self>,
|
||||
ctx: RpcContext<'_, Node>,
|
||||
handles: RethRpcServerHandles,
|
||||
) -> eyre::Result<()>;
|
||||
@@ -106,20 +106,24 @@ pub trait OnRpcStarted<Node: FullNodeComponents>: Send {
|
||||
|
||||
impl<Node, F> OnRpcStarted<Node> for F
|
||||
where
|
||||
F: Fn(RpcContext<'_, Node>, RethRpcServerHandles) -> eyre::Result<()> + Send,
|
||||
F: FnOnce(RpcContext<'_, Node>, RethRpcServerHandles) -> eyre::Result<()> + Send,
|
||||
Node: FullNodeComponents,
|
||||
{
|
||||
fn on_rpc_started(
|
||||
&self,
|
||||
self: Box<Self>,
|
||||
ctx: RpcContext<'_, Node>,
|
||||
handles: RethRpcServerHandles,
|
||||
) -> eyre::Result<()> {
|
||||
self(ctx, handles)
|
||||
(*self)(ctx, handles)
|
||||
}
|
||||
}
|
||||
|
||||
impl<Node: FullNodeComponents> OnRpcStarted<Node> for () {
|
||||
fn on_rpc_started(&self, _: RpcContext<'_, Node>, _: RethRpcServerHandles) -> eyre::Result<()> {
|
||||
fn on_rpc_started(
|
||||
self: Box<Self>,
|
||||
_: RpcContext<'_, Node>,
|
||||
_: RethRpcServerHandles,
|
||||
) -> eyre::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -127,21 +131,21 @@ impl<Node: FullNodeComponents> OnRpcStarted<Node> for () {
|
||||
/// Event hook that is called when the rpc server is started.
|
||||
pub trait ExtendRpcModules<Node: FullNodeComponents>: Send {
|
||||
/// The hook that is called once the rpc server is started.
|
||||
fn extend_rpc_modules(&self, ctx: RpcContext<'_, Node>) -> eyre::Result<()>;
|
||||
fn extend_rpc_modules(self: Box<Self>, ctx: RpcContext<'_, Node>) -> eyre::Result<()>;
|
||||
}
|
||||
|
||||
impl<Node, F> ExtendRpcModules<Node> for F
|
||||
where
|
||||
F: Fn(RpcContext<'_, Node>) -> eyre::Result<()> + Send,
|
||||
F: FnOnce(RpcContext<'_, Node>) -> eyre::Result<()> + Send,
|
||||
Node: FullNodeComponents,
|
||||
{
|
||||
fn extend_rpc_modules(&self, ctx: RpcContext<'_, Node>) -> eyre::Result<()> {
|
||||
self(ctx)
|
||||
fn extend_rpc_modules(self: Box<Self>, ctx: RpcContext<'_, Node>) -> eyre::Result<()> {
|
||||
(*self)(ctx)
|
||||
}
|
||||
}
|
||||
|
||||
impl<Node: FullNodeComponents> ExtendRpcModules<Node> for () {
|
||||
fn extend_rpc_modules(&self, _: RpcContext<'_, Node>) -> eyre::Result<()> {
|
||||
fn extend_rpc_modules(self: Box<Self>, _: RpcContext<'_, Node>) -> eyre::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user