Skip to content

refactor: qualify free-function calls and generalize public API params - #668

Open
varex83agent wants to merge 1 commit into
mainfrom
feat/fix-605
Open

refactor: qualify free-function calls and generalize public API params#668
varex83agent wants to merge 1 commit into
mainfrom
feat/fix-605

Conversation

@varex83agent

Copy link
Copy Markdown
Collaborator

Summary

Mechanical, no-behavior-change style sweep addressing the two convention gaps in #605.

Part A — Qualify free-function calls

Free (standalone) functions are now imported via their parent module and called qualified (module::func()) instead of being imported bare. Types, structs, enums, constants, and traits remain imported bare (traits must stay bare for method resolution). Touched ~30 production use statements across app, cli, cluster, consensus, core, dkg, eth2api, eth2util, p2p, priority, and relay-server (e.g. peer_name, hash_proto, sig_to_eth2, to_0x_hex, validate_addresses, hash_typed_data, fork_version_to_chain_id, create_dist_validators, the agg_* helpers, etc.). Test-only (#[cfg(test)]) imports and public pub use re-exports were intentionally left untouched.

Part B — Generalize public API parameter types

Applied the established generic idiom consistently within each module:

  • eth2util::network: valid_network / network_to_genesis_time now take impl AsRef<str> (matching sibling network_to_fork_version).
  • cluster::version: support_pregen_registrations / support_node_signatures now take impl AsRef<str>.
  • k1util::load / save now take impl AsRef<Path> (matching the rest of the workspace); redundant borrows at call sites cleaned up.
  • build-proto::compile_protos now takes impl AsRef<Path> instead of &str.

Part C — Conventions doc

Updated .claude/skills/rust-style/SKILL.md with a new Imports section (import modules/types, not free functions) and expanded the Generalized Parameter Types guidance (public APIs accept impl AsRef<str>/impl AsRef<Path>/impl Into<String>/impl IntoIterator where only the borrowed/converted form is needed; full uniformity is not the goal).

Scope notes

Per the issue's Note, this stays scoped to public APIs and mixed conventions within the same module — private helpers and hot internal paths keep concrete types. Widely-established cross-crate bare imports that would cause large call-site churn without fixing an in-module inconsistency (e.g. peer_id_from_key / verify_p2p_key used bare in ~10 files) were left as-is to avoid over-reach.

Quality gates

  • cargo +nightly fmt --all — clean
  • cargo clippy --workspace --all-targets --all-features -- -D warnings — clean
  • cargo test --workspace --all-features — passing

Closes #605

🤖 Generated with Claude Code

#605)

Part A — qualify free-function calls: import parent modules/types instead
of importing free (standalone) functions bare, and call them qualified
(module::func()). Traits, types, structs, enums and constants stay imported
bare. Touches ~30 production use statements across app, cli, cluster,
consensus, core, dkg, eth2api, eth2util, p2p, priority, relay-server.

Part B — generalize public API parameter types for consistency within
modules:
- eth2util::network: valid_network / network_to_genesis_time now take
  impl AsRef<str> (matching sibling network_to_fork_version).
- cluster::version: support_pregen_registrations / support_node_signatures
  now take impl AsRef<str>.
- k1util::load / save now take impl AsRef<Path> (matching the rest of the
  workspace).
- build-proto::compile_protos now takes impl AsRef<Path> instead of &str.

Part C — document both conventions in the rust-style skill: import
modules/types not free functions; public APIs accept
impl AsRef<str>/impl AsRef<Path>/impl Into<String>/impl IntoIterator where
only the borrowed/converted form is needed.

No behavior change.

Co-Authored-By: Bohdan Ohorodnii <35969035+varex83@users.noreply.github.com>
/// support.
pub(crate) mod u256_dec_serde {
use alloy::primitives::U256;
use pluto_ssz::serde_utils::strip_0x_prefix;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not consistent with above change


{
let handle_clone = handle.clone();
let sub = internal_subscriber(move |duty, set| {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do the same thing for internal_subscriber and threshold_subscriber?

name,
p2p_context::P2PContext,
utils::{
filter_direct_quic_addrs, has_direct_quic_conn, has_direct_tcp_conn, is_quic_addr,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about these

gater::ConnGater,
p2p::{Node, NodeType},
p2p_context::P2PContext,
peer::{MutablePeer, Peer, peer_id_from_key, verify_p2p_key},

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

peer_id_from_key, verify_p2p_key

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Qualify free-function calls and prefer generic parameter types in public APIs

2 participants