Skip to content

Commit

Permalink
fmt: format doc comments (paradigmxyz#5308)
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes authored Nov 5, 2023
1 parent f9c46bf commit 470449f
Show file tree
Hide file tree
Showing 26 changed files with 207 additions and 160 deletions.
7 changes: 3 additions & 4 deletions bin/reth/src/cli/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,10 @@ where
/// # Example
///
/// ```rust
/// use reth::cli::components::RethRpcServerHandles;
/// use reth::rpc::api::EthApiClient;
/// use reth::{cli::components::RethRpcServerHandles, rpc::api::EthApiClient};
/// # async fn t(handles: RethRpcServerHandles) {
/// let client = handles.rpc.http_client().expect("http server not started");
/// let block_number = client.block_number().await.unwrap();
/// let client = handles.rpc.http_client().expect("http server not started");
/// let block_number = client.block_number().await.unwrap();
/// # }
/// ```
#[derive(Debug, Clone)]
Expand Down
2 changes: 1 addition & 1 deletion bin/reth/src/dirs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ pub trait XdgPath {
/// # Example
///
/// ```
/// use reth::dirs::{PlatformPath, DataDirPath};
/// use reth::dirs::{DataDirPath, PlatformPath};
/// use std::str::FromStr;
///
/// // Resolves to the platform-specific database path
Expand Down
8 changes: 3 additions & 5 deletions crates/consensus/common/src/calc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,11 @@ pub fn base_block_reward(
/// let total_difficulty = U256::from(2_235_668_675_900usize);
/// let number_of_ommers = 1;
///
/// let reward = base_block_reward(&MAINNET, block_number, block_difficulty, total_difficulty).map(|reward| block_reward(reward, 1));
/// let reward = base_block_reward(&MAINNET, block_number, block_difficulty, total_difficulty)
/// .map(|reward| block_reward(reward, 1));
///
/// // The base block reward is 5 ETH, and the ommer inclusion reward is 1/32th of 5 ETH.
/// assert_eq!(
/// reward.unwrap(),
/// ETH_TO_WEI * 5 + ((ETH_TO_WEI * 5) >> 5)
/// );
/// assert_eq!(reward.unwrap(), ETH_TO_WEI * 5 + ((ETH_TO_WEI * 5) >> 5));
/// ```
///
/// # References
Expand Down
30 changes: 20 additions & 10 deletions crates/metrics/metrics-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ mod with_attrs;
///
/// Sample usage:
/// ```
/// use reth_metrics_derive::Metrics;
/// use metrics::{Counter, Gauge, Histogram};
/// use reth_metrics_derive::Metrics;
///
/// #[derive(Metrics)]
/// #[metrics(scope = "metrics_custom")]
Expand All @@ -43,7 +43,7 @@ mod with_attrs;
/// counter: Counter,
/// /// A renamed histogram.
/// #[metric(rename = "histogram")]
/// histo: Histogram
/// histo: Histogram,
/// }
/// ```
///
Expand All @@ -56,7 +56,7 @@ mod with_attrs;
/// /// Some doc comment
/// counter: metrics::Counter,
/// /// A renamed histogram.
/// histo: metrics::Histogram
/// histo: metrics::Histogram,
/// }
///
/// impl Default for CustomMetrics {
Expand All @@ -73,9 +73,18 @@ mod with_attrs;
/// impl CustomMetrics {
/// /// Describe all exposed metrics
/// pub fn describe() {
/// metrics::describe_gauge!("metrics_custom_gauge", "A gauge with doc comment description.");
/// metrics::describe_gauge!("metrics_custom_second_gauge", "A gauge with metric attribute description.");
/// metrics::describe_counter!("metrics_custom_counter", "Metric attribute description will be preferred over doc comment.");
/// metrics::describe_gauge!(
/// "metrics_custom_gauge",
/// "A gauge with doc comment description."
/// );
/// metrics::describe_gauge!(
/// "metrics_custom_second_gauge",
/// "A gauge with metric attribute description."
/// );
/// metrics::describe_counter!(
/// "metrics_custom_counter",
/// "Metric attribute description will be preferred over doc comment."
/// );
/// metrics::describe_histogram!("metrics_custom_histogram", "A renamed histogram.");
/// }
/// }
Expand Down Expand Up @@ -110,13 +119,14 @@ mod with_attrs;
///
/// impl DynamicScopeMetrics {
/// pub fn new(scope: &str) -> Self {
/// Self {
/// gauge: metrics::register_gauge!(format!("{}{}{}", scope, "_", "gauge"))
/// }
/// Self { gauge: metrics::register_gauge!(format!("{}{}{}", scope, "_", "gauge")) }
/// }
///
/// pub fn describe(scope: &str) {
/// metrics::describe_gauge!(format!("{}{}{}", scope, "_", "gauge"), "A gauge with doc comment description.");
/// metrics::describe_gauge!(
/// format!("{}{}{}", scope, "_", "gauge"),
/// "A gauge with doc comment description."
/// );
/// }
/// }
///
Expand Down
37 changes: 16 additions & 21 deletions crates/net/discv4/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,36 +193,31 @@ impl Discv4 {
///
/// ```
/// # use std::io;
/// use std::net::SocketAddr;
/// use std::str::FromStr;
/// use rand::thread_rng;
/// use secp256k1::SECP256K1;
/// use reth_primitives::{NodeRecord, PeerId};
/// use reth_discv4::{Discv4, Discv4Config};
/// use reth_primitives::{NodeRecord, PeerId};
/// use secp256k1::SECP256K1;
/// use std::{net::SocketAddr, str::FromStr};
/// # async fn t() -> io::Result<()> {
/// // generate a (random) keypair
/// let mut rng = thread_rng();
/// let (secret_key, pk) = SECP256K1.generate_keypair(&mut rng);
/// let id = PeerId::from_slice(&pk.serialize_uncompressed()[1..]);
/// let mut rng = thread_rng();
/// let (secret_key, pk) = SECP256K1.generate_keypair(&mut rng);
/// let id = PeerId::from_slice(&pk.serialize_uncompressed()[1..]);
///
/// let socket = SocketAddr::from_str("0.0.0.0:0").unwrap();
/// let local_enr = NodeRecord {
/// address: socket.ip(),
/// tcp_port: socket.port(),
/// udp_port: socket.port(),
/// id,
/// };
/// let config = Discv4Config::default();
/// let socket = SocketAddr::from_str("0.0.0.0:0").unwrap();
/// let local_enr =
/// NodeRecord { address: socket.ip(), tcp_port: socket.port(), udp_port: socket.port(), id };
/// let config = Discv4Config::default();
///
/// let(discv4, mut service) = Discv4::bind(socket, local_enr, secret_key, config).await.unwrap();
/// let (discv4, mut service) = Discv4::bind(socket, local_enr, secret_key, config).await.unwrap();
///
/// // get an update strea
/// let updates = service.update_stream();
/// // get an update strea
/// let updates = service.update_stream();
///
/// let _handle = service.spawn();
/// let _handle = service.spawn();
///
/// // lookup the local node in the DHT
/// let _discovered = discv4.lookup_self().await.unwrap();
/// // lookup the local node in the DHT
/// let _discovered = discv4.lookup_self().await.unwrap();
///
/// # Ok(())
/// # }
Expand Down
8 changes: 5 additions & 3 deletions crates/net/dns/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,13 @@ impl<R: Resolver> DnsDiscoveryService<R> {
/// Creates a new instance of the [DnsDiscoveryService] using the given settings.
///
/// ```
/// use std::sync::Arc;
/// use reth_dns_discovery::{DnsDiscoveryService, DnsResolver};
/// use std::sync::Arc;
/// # fn t() {
/// let service =
/// DnsDiscoveryService::new(Arc::new(DnsResolver::from_system_conf().unwrap()), Default::default());
/// let service = DnsDiscoveryService::new(
/// Arc::new(DnsResolver::from_system_conf().unwrap()),
/// Default::default(),
/// );
/// # }
/// ```
pub fn new(resolver: Arc<R>, config: DnsDiscoveryConfig) -> Self {
Expand Down
4 changes: 2 additions & 2 deletions crates/net/dns/src/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ impl<P: ConnectionProvider> Resolver for AsyncResolver<P> {
///
/// ```
/// # fn t() {
/// use reth_dns_discovery::resolver::DnsResolver;
/// let resolver = DnsResolver::from_system_conf().unwrap();
/// use reth_dns_discovery::resolver::DnsResolver;
/// let resolver = DnsResolver::from_system_conf().unwrap();
/// # }
/// ```
///
Expand Down
20 changes: 9 additions & 11 deletions crates/net/downloaders/src/bodies/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,16 @@ impl TaskDownloader {
/// # Example
///
/// ```
/// use std::sync::Arc;
/// use reth_downloaders::bodies::bodies::BodiesDownloaderBuilder;
/// use reth_downloaders::bodies::task::TaskDownloader;
/// use reth_interfaces::consensus::Consensus;
/// use reth_interfaces::p2p::bodies::client::BodiesClient;
/// use reth_db::database::Database;
/// fn t<B: BodiesClient + 'static, DB: Database + 'static>(client: Arc<B>, consensus:Arc<dyn Consensus>, db: Arc<DB>) {
/// let downloader = BodiesDownloaderBuilder::default().build(
/// client,
/// consensus,
/// db
/// );
/// use reth_downloaders::bodies::{bodies::BodiesDownloaderBuilder, task::TaskDownloader};
/// use reth_interfaces::{consensus::Consensus, p2p::bodies::client::BodiesClient};
/// use std::sync::Arc;
/// fn t<B: BodiesClient + 'static, DB: Database + 'static>(
/// client: Arc<B>,
/// consensus: Arc<dyn Consensus>,
/// db: Arc<DB>,
/// ) {
/// let downloader = BodiesDownloaderBuilder::default().build(client, consensus, db);
/// let downloader = TaskDownloader::spawn(downloader);
/// }
/// ```
Expand Down
5 changes: 2 additions & 3 deletions crates/net/eth-wire/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ use reth_primitives::{Chain, ForkId, PeerId, B256, U256};
///
/// # Example
/// ```
/// use reth_eth_wire::EthVersion;
/// use reth_primitives::{Chain, U256, B256, MAINNET_GENESIS_HASH, MAINNET, Hardfork};
/// use reth_eth_wire::types::Status;
/// use reth_eth_wire::{types::Status, EthVersion};
/// use reth_primitives::{Chain, Hardfork, B256, MAINNET, MAINNET_GENESIS_HASH, U256};
///
/// // this is just an example status message!
/// let status = Status::builder()
Expand Down
4 changes: 2 additions & 2 deletions crates/net/eth-wire/src/hello.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ impl HelloMessage {
/// Starts a new `HelloMessageBuilder`
///
/// ```
/// use secp256k1::{SECP256K1, SecretKey};
/// use reth_ecies::util::pk2id;
/// use reth_eth_wire::HelloMessage;
/// use secp256k1::{SecretKey, SECP256K1};
/// let secret_key = SecretKey::new(&mut rand::thread_rng());
/// let id = pk2id(&secret_key.public_key(SECP256K1));
/// let id = pk2id(&secret_key.public_key(SECP256K1));
/// let status = HelloMessage::builder(id).build();
/// ```
pub fn builder(id: PeerId) -> HelloMessageBuilder {
Expand Down
6 changes: 2 additions & 4 deletions crates/net/network/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,8 @@ impl NetworkConfigBuilder {
/// # use reth_eth_wire::HelloMessage;
/// # use reth_network::NetworkConfigBuilder;
/// # fn builder(builder: NetworkConfigBuilder) {
/// let peer_id = builder.get_peer_id();
/// builder.hello_message(
/// HelloMessage::builder(peer_id).build()
/// );
/// let peer_id = builder.get_peer_id();
/// builder.hello_message(HelloMessage::builder(peer_id).build());
/// # }
/// ```
pub fn hello_message(mut self, hello_message: HelloMessage) -> Self {
Expand Down
14 changes: 5 additions & 9 deletions crates/net/network/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,17 @@
//!
//! ```
//! # async fn launch() {
//! use reth_network::config::rng_secret_key;
//! use reth_network::{NetworkConfig, NetworkManager};
//! use reth_provider::test_utils::NoopProvider;
//! use reth_network::{config::rng_secret_key, NetworkConfig, NetworkManager};
//! use reth_primitives::mainnet_nodes;
//! use reth_provider::test_utils::NoopProvider;
//!
//! // This block provider implementation is used for testing purposes.
//! let client = NoopProvider::default();
//!
//! // The key that's used for encrypting sessions and to identify our node.
//! let local_key = rng_secret_key();
//!
//! let config = NetworkConfig::builder(local_key).boot_nodes(
//! mainnet_nodes()
//! ).build(client);
//! let config = NetworkConfig::builder(local_key).boot_nodes(mainnet_nodes()).build(client);
//!
//! // create the network instance
//! let network = NetworkManager::new(config).await.unwrap();
Expand All @@ -74,11 +71,10 @@
//! ### Configure all components of the Network with the [`NetworkBuilder`]
//!
//! ```
//! use reth_network::{config::rng_secret_key, NetworkConfig, NetworkManager};
//! use reth_primitives::mainnet_nodes;
//! use reth_provider::test_utils::NoopProvider;
//! use reth_transaction_pool::TransactionPool;
//! use reth_primitives::mainnet_nodes;
//! use reth_network::config::rng_secret_key;
//! use reth_network::{NetworkConfig, NetworkManager};
//! async fn launch<Pool: TransactionPool>(pool: Pool) {
//! // This block provider implementation is used for testing purposes.
//! let client = NoopProvider::default();
Expand Down
5 changes: 2 additions & 3 deletions crates/net/network/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,10 @@ where
/// components of the network
///
/// ```
/// use reth_network::{config::rng_secret_key, NetworkConfig, NetworkManager};
/// use reth_primitives::mainnet_nodes;
/// use reth_provider::test_utils::NoopProvider;
/// use reth_transaction_pool::TransactionPool;
/// use reth_primitives::mainnet_nodes;
/// use reth_network::config::rng_secret_key;
/// use reth_network::{NetworkConfig, NetworkManager};
/// async fn launch<Pool: TransactionPool>(pool: Pool) {
/// // This block provider implementation is used for testing purposes.
/// let client = NoopProvider::default();
Expand Down
4 changes: 1 addition & 3 deletions crates/net/network/tests/it/clique/geth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ use std::{
/// # let clique = async {
///
/// // this creates a funded geth
/// let clique_geth = Geth::new()
/// .p2p_port(30303)
/// .chain_id(1337u64);
/// let clique_geth = Geth::new().p2p_port(30303).chain_id(1337u64);
///
/// // build the funded geth, generating a random signing key and enabling clique
/// let mut clique = CliqueGethInstance::new(clique_geth, None).await;
Expand Down
7 changes: 3 additions & 4 deletions crates/rpc/ipc/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,11 @@ impl IpcTransportClientBuilder {
/// Try to establish the connection.
///
/// ```
/// use jsonrpsee::rpc_params;
/// use jsonrpsee::{core::client::ClientT, rpc_params};
/// use reth_ipc::client::IpcClientBuilder;
/// use jsonrpsee::core::client::ClientT;
/// # async fn run_client() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
/// let client = IpcClientBuilder::default().build("/tmp/my-uds").await?;
/// let response: String = client.request("say_hello", rpc_params![]).await?;
/// let client = IpcClientBuilder::default().build("/tmp/my-uds").await?;
/// let response: String = client.request("say_hello", rpc_params![]).await?;
/// # Ok(())
/// # }
/// ```
Expand Down
1 change: 0 additions & 1 deletion crates/rpc/ipc/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,6 @@ impl<B, L> Builder<B, L> {
/// # Examples
///
/// ```rust
///
/// #[tokio::main]
/// async fn main() {
/// let builder = tower::ServiceBuilder::new();
Expand Down
Loading

0 comments on commit 470449f

Please sign in to comment.