Skip to content

Commit b17b1f2

Browse files
authored
docs: Format code in doc comments (#2895)
## Description This enables the unstable rustfmt option to format the code in docs. Should make our examples a lot more consistent. ## Breaking Changes <!-- Optional, if there are any breaking changes document them, including how to migrate older code. --> ## Notes & open questions This is unstable, so there might be some churn or bad results. But I don't think the churn should be much of an issue for us. ## Change checklist - [x] Self-review. - [x] Documentation updates following the [style guide](https://rust-lang.github.io/rfcs/1574-more-api-documentation-conventions.html#appendix-a-full-conventions-text), if relevant. - [x] Tests if relevant. - [x] All breaking changes documented.
1 parent 8d8baf5 commit b17b1f2

File tree

16 files changed

+50
-51
lines changed

16 files changed

+50
-51
lines changed

Makefile.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ args = [
1010
"--config",
1111
"unstable_features=true",
1212
"--config",
13-
"imports_granularity=Crate,group_imports=StdExternalCrate,reorder_imports=true",
13+
"imports_granularity=Crate,group_imports=StdExternalCrate,reorder_imports=true,format_code_in_doc_comments=true",
1414
]
1515

1616
[tasks.format-check]
@@ -24,5 +24,5 @@ args = [
2424
"--config",
2525
"unstable_features=true",
2626
"--config",
27-
"imports_granularity=Crate,group_imports=StdExternalCrate,reorder_imports=true",
27+
"imports_granularity=Crate,group_imports=StdExternalCrate,reorder_imports=true,format_code_in_doc_comments=true",
2828
]

iroh-cli/tests/cli.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,8 @@ fn match_provide_output<T: Read>(
865865
/// (r"hello world!", 1),
866866
/// (r"\S*$", 1),
867867
/// (r"\d{2}/\d{2}/\d{4}", 3),
868-
/// ]);
868+
/// ],
869+
/// );
869870
/// ```
870871
fn assert_matches_line<R: BufRead, I>(reader: R, expressions: I) -> Vec<(usize, Vec<String>)>
871872
where

iroh-dns-server/src/http.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,6 @@ pub(crate) fn create_app(state: AppState, rate_limit_config: &RateLimitConfig) -
237237
}
238238

239239
/// Record request metrics.
240-
///
241240
// TODO:
242241
// * Request duration would be much better tracked as a histogram.
243242
// * It would be great to attach labels to the metrics, so that the recorded metrics

iroh-metrics/src/metrics.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313
//!
1414
//! # Example:
1515
//! ```rust
16-
//! use iroh_metrics::{inc, inc_by};
17-
//! use iroh_metrics::core::{Core, Metric, Counter};
16+
//! use iroh_metrics::{
17+
//! core::{Core, Counter, Metric},
18+
//! inc, inc_by,
19+
//! };
1820
//! use struct_iterable::Iterable;
1921
//!
2022
//! #[derive(Debug, Clone, Iterable)]
@@ -25,15 +27,17 @@
2527
//! impl Default for Metrics {
2628
//! fn default() -> Self {
2729
//! Self {
28-
//! things_added: Counter::new("things_added tracks the number of things we have added"),
30+
//! things_added: Counter::new(
31+
//! "things_added tracks the number of things we have added",
32+
//! ),
2933
//! }
3034
//! }
3135
//! }
3236
//!
3337
//! impl Metric for Metrics {
34-
//! fn name() -> &'static str {
38+
//! fn name() -> &'static str {
3539
//! "my_metrics"
36-
//! }
40+
//! }
3741
//! }
3842
//!
3943
//! Core::init(|reg, metrics| {

iroh-net/src/discovery.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@
4646
//! [`PkarrPublisher`] and [`DnsDiscovery`]:
4747
//!
4848
//! ```no_run
49-
//! use iroh_net::discovery::dns::DnsDiscovery;
50-
//! use iroh_net::discovery::pkarr::PkarrPublisher;
51-
//! use iroh_net::discovery::ConcurrentDiscovery;
52-
//! use iroh_net::key::SecretKey;
53-
//! use iroh_net::Endpoint;
49+
//! use iroh_net::{
50+
//! discovery::{dns::DnsDiscovery, pkarr::PkarrPublisher, ConcurrentDiscovery},
51+
//! key::SecretKey,
52+
//! Endpoint,
53+
//! };
5454
//!
5555
//! # async fn wrapper() -> anyhow::Result<()> {
5656
//! let secret_key = SecretKey::generate();

iroh-net/src/discovery/local_swarm_discovery.rs

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,28 @@
77
//!
88
//! ```
99
//! use std::time::Duration;
10-
//! use iroh_net::endpoint::{Source, Endpoint};
10+
//!
11+
//! use iroh_net::endpoint::{Endpoint, Source};
1112
//!
1213
//! #[tokio::main]
1314
//! async fn main() {
14-
//! let recent = Duration::from_secs(600); // 10 minutes in seconds
15+
//! let recent = Duration::from_secs(600); // 10 minutes in seconds
1516
//!
16-
//! let endpoint = Endpoint::builder().bind().await.unwrap();
17-
//! let remotes = endpoint.remote_info_iter();
18-
//! let locally_discovered: Vec<_> = remotes
19-
//! .filter(|remote| {
20-
//! remote
21-
//! .sources()
22-
//! .iter()
23-
//! .any(|(source, duration)| {
24-
//! if let Source::Discovery { name } = source {
25-
//! name == iroh_net::discovery::local_swarm_discovery::NAME && *duration <= recent
26-
//! } else {
27-
//! false
28-
//! }
29-
//! })
30-
//! })
31-
//! .collect();
32-
//! println!("locally discovered nodes: {locally_discovered:?}");
17+
//! let endpoint = Endpoint::builder().bind().await.unwrap();
18+
//! let remotes = endpoint.remote_info_iter();
19+
//! let locally_discovered: Vec<_> = remotes
20+
//! .filter(|remote| {
21+
//! remote.sources().iter().any(|(source, duration)| {
22+
//! if let Source::Discovery { name } = source {
23+
//! name == iroh_net::discovery::local_swarm_discovery::NAME
24+
//! && *duration <= recent
25+
//! } else {
26+
//! false
27+
//! }
28+
//! })
29+
//! })
30+
//! .collect();
31+
//! println!("locally discovered nodes: {locally_discovered:?}");
3332
//! }
3433
//! ```
3534
use std::{

iroh-net/src/endpoint.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,7 @@ impl Endpoint {
845845
///
846846
/// # let rt = tokio::runtime::Builder::new_current_thread().enable_all().build().unwrap();
847847
/// # rt.block_on(async move {
848-
/// let mep = Endpoint::builder().bind().await.unwrap();
848+
/// let mep = Endpoint::builder().bind().await.unwrap();
849849
/// let _addrs = mep.direct_addresses().next().await;
850850
/// # });
851851
/// ```

iroh-net/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,7 @@
184184
//! ```no_run
185185
//! use anyhow::{Context, Result};
186186
//! use futures_lite::StreamExt;
187-
//! use iroh_net::ticket::NodeTicket;
188-
//! use iroh_net::{Endpoint, NodeAddr};
187+
//! use iroh_net::{ticket::NodeTicket, Endpoint, NodeAddr};
189188
//!
190189
//! async fn accept() -> Result<()> {
191190
//! // To accept connections at least one ALPN must be configured.

iroh-net/src/relay/codec.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ pub(super) const PROTOCOL_VERSION: usize = 3;
6060
/// * client responds to any FrameType::Ping with a FrameType::Pong
6161
/// * clients sends FrameType::SendPacket
6262
/// * server then sends FrameType::RecvPacket to recipient
63-
///
6463
6564
const PREFERRED: u8 = 1u8;
6665
/// indicates this is NOT the client's home node

iroh-net/src/relay/server/clients.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use crate::key::PublicKey;
1818
const RETRIES: usize = 3;
1919

2020
/// Represents a connection to a client.
21-
///
2221
// TODO: expand to allow for _multiple connections_ associated with a single PublicKey. This
2322
// introduces some questions around which connection should be prioritized when forwarding packets
2423
//

0 commit comments

Comments
 (0)