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

@@ -141,14 +141,14 @@ pub struct NodeBuilder<DB> {
impl NodeBuilder<()> {
/// Create a new [`NodeBuilder`].
pub fn new(config: NodeConfig) -> Self {
pub const fn new(config: NodeConfig) -> Self {
Self { config, database: () }
}
}
impl<DB> NodeBuilder<DB> {
/// Returns a reference to the node builder's config.
pub fn config(&self) -> &NodeConfig {
pub const fn config(&self) -> &NodeConfig {
&self.config
}
@@ -160,7 +160,7 @@ impl<DB> NodeBuilder<DB> {
/// Preconfigure the builder with the context to launch the node.
///
/// This provides the task executor and the data directory for the node.
pub fn with_launch_context(
pub const fn with_launch_context(
self,
task_executor: TaskExecutor,
data_dir: ChainPath<DataDirPath>,
@@ -221,12 +221,12 @@ pub struct WithLaunchContext<Builder> {
impl<Builder> WithLaunchContext<Builder> {
/// Returns a reference to the task executor.
pub fn task_executor(&self) -> &TaskExecutor {
pub const fn task_executor(&self) -> &TaskExecutor {
&self.task_executor
}
/// Returns a reference to the data directory.
pub fn data_dir(&self) -> &ChainPath<DataDirPath> {
pub const fn data_dir(&self) -> &ChainPath<DataDirPath> {
&self.data_dir
}
}
@@ -236,7 +236,7 @@ where
DB: Database + DatabaseMetrics + DatabaseMetadata + Clone + Unpin + 'static,
{
/// Returns a reference to the node builder's config.
pub fn config(&self) -> &NodeConfig {
pub const fn config(&self) -> &NodeConfig {
self.builder.config()
}
@@ -411,7 +411,7 @@ where
/// Check that the builder can be launched
///
/// This is useful when writing tests to ensure that the builder is configured correctly.
pub fn check_launch(self) -> Self {
pub const fn check_launch(self) -> Self {
self
}
}
@@ -434,7 +434,7 @@ pub struct BuilderContext<Node: FullNodeTypes> {
impl<Node: FullNodeTypes> BuilderContext<Node> {
/// Create a new instance of [BuilderContext]
pub fn new(
pub const fn new(
head: Head,
provider: Node::Provider,
executor: TaskExecutor,
@@ -446,31 +446,31 @@ impl<Node: FullNodeTypes> BuilderContext<Node> {
}
/// Returns the configured provider to interact with the blockchain.
pub fn provider(&self) -> &Node::Provider {
pub const fn provider(&self) -> &Node::Provider {
&self.provider
}
/// Returns the current head of the blockchain at launch.
pub fn head(&self) -> Head {
pub const fn head(&self) -> Head {
self.head
}
/// Returns the config of the node.
pub fn config(&self) -> &NodeConfig {
pub const fn config(&self) -> &NodeConfig {
&self.config
}
/// Returns the data dir of the node.
///
/// This gives access to all relevant files and directories of the node's datadir.
pub fn data_dir(&self) -> &ChainPath<DataDirPath> {
pub const fn data_dir(&self) -> &ChainPath<DataDirPath> {
&self.data_dir
}
/// Returns the executor of the node.
///
/// This can be used to execute async tasks or functions during the setup.
pub fn task_executor(&self) -> &TaskExecutor {
pub const fn task_executor(&self) -> &TaskExecutor {
&self.executor
}

View File

@@ -63,7 +63,7 @@ pub(crate) struct NodeTypesAdapter<T: FullNodeTypes> {
impl<T: FullNodeTypes> NodeTypesAdapter<T> {
/// Create a new adapter from the given node types.
pub(crate) fn new(database: T::DB) -> Self {
pub(crate) const fn new(database: T::DB) -> Self {
Self { database }
}
}
@@ -223,7 +223,7 @@ impl<T: FullNodeTypes, CB: NodeComponentsBuilder<T>> NodeBuilderWithComponents<T
/// Check that the builder can be launched
///
/// This is useful when writing tests to ensure that the builder is configured correctly.
pub fn check_launch(self) -> Self {
pub const fn check_launch(self) -> Self {
self
}
}

View File

@@ -40,7 +40,7 @@ impl LaunchContext {
}
/// Attaches a database to the launch context.
pub fn with<DB>(self, database: DB) -> LaunchContextWith<DB> {
pub const fn with<DB>(self, database: DB) -> LaunchContextWith<DB> {
LaunchContextWith { inner: self, attachment: database }
}
@@ -156,12 +156,12 @@ impl<T> LaunchContextWith<T> {
}
/// Returns the data directory.
pub fn data_dir(&self) -> &ChainPath<DataDirPath> {
pub const fn data_dir(&self) -> &ChainPath<DataDirPath> {
&self.inner.data_dir
}
/// Returns the task executor.
pub fn task_executor(&self) -> &TaskExecutor {
pub const fn task_executor(&self) -> &TaskExecutor {
&self.inner.task_executor
}
@@ -267,7 +267,7 @@ impl<R> LaunchContextWith<Attached<WithConfigs, R>> {
}
/// Returns true if the node is configured as --dev
pub fn is_dev(&self) -> bool {
pub const fn is_dev(&self) -> bool {
self.node_config().dev.dev
}
@@ -357,7 +357,7 @@ where
}
/// Returns the configured ProviderFactory.
pub fn provider_factory(&self) -> &ProviderFactory<DB> {
pub const fn provider_factory(&self) -> &ProviderFactory<DB> {
self.right()
}

View File

@@ -66,7 +66,7 @@ pub struct DefaultNodeLauncher {
impl DefaultNodeLauncher {
/// Create a new instance of the default node launcher.
pub fn new(task_executor: TaskExecutor, data_dir: ChainPath<DataDirPath>) -> Self {
pub const fn new(task_executor: TaskExecutor, data_dir: ChainPath<DataDirPath>) -> Self {
Self { ctx: LaunchContext::new(task_executor, data_dir) }
}
}

View File

@@ -64,12 +64,12 @@ impl<Node: FullNodeComponents> FullNode<Node> {
}
/// Returns the [RpcServerHandle] to the started rpc server.
pub fn rpc_server_handle(&self) -> &RpcServerHandle {
pub const fn rpc_server_handle(&self) -> &RpcServerHandle {
&self.rpc_server_handles.rpc
}
/// Returns the [AuthServerHandle] to the started authenticated engine API server.
pub fn auth_server_handle(&self) -> &AuthServerHandle {
pub const fn auth_server_handle(&self) -> &AuthServerHandle {
&self.rpc_server_handles.auth
}

View File

@@ -220,12 +220,12 @@ pub struct RpcContext<'a, Node: FullNodeComponents> {
impl<'a, Node: FullNodeComponents> RpcContext<'a, Node> {
/// Returns the config of the node.
pub fn config(&self) -> &NodeConfig {
pub const fn config(&self) -> &NodeConfig {
self.config
}
/// Returns a reference to the configured node.
pub fn node(&self) -> &Node {
pub const fn node(&self) -> &Node {
&self.node
}