Skip to content

Commit 38a0745

Browse files
chore: Format imports using rustfmt (#2812)
## Description This enables a strict style in rustfmt to format imports statements. It needs rust nightly for rustfmt to be able to do this. To not make the `cargo fmt` from stable rust really noisy it does not add a rustfmt.toml file, instead it adds a `cargo-make` task to automate running this locally. This same task is used in CI to run the formatter. The `Crate`m formatting will be preserved by the default configuration of rust-analyzer, which makes external contributions easier as well, most folks shouldn't be running into this formatter. ## Breaking Changes <!-- Optional, if there are any breaking changes document them, including how to migrate older code. --> ## Notes & open questions I guess we need buy-in from everyone on the team for this. ## 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. --------- Co-authored-by: Diva M <[email protected]> Co-authored-by: Divma <[email protected]>
1 parent 615cbd6 commit 38a0745

30 files changed

+175
-156
lines changed

Makefile.toml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Use cargo-make to run tasks here: https://crates.io/crates/cargo-make
2+
3+
[tasks.format]
4+
workspace = false
5+
command = "cargo"
6+
args = [
7+
"fmt",
8+
"--all",
9+
"--",
10+
"--config",
11+
"unstable_features=true",
12+
"--config",
13+
"imports_granularity=Crate,group_imports=StdExternalCrate,reorder_imports=true",
14+
]
15+
16+
[tasks.format-check]
17+
workspace = false
18+
command = "cargo"
19+
args = [
20+
"fmt",
21+
"--all",
22+
"--check",
23+
"--",
24+
"--config",
25+
"unstable_features=true",
26+
"--config",
27+
"imports_granularity=Crate,group_imports=StdExternalCrate,reorder_imports=true",
28+
]

iroh-blobs/examples/connect/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
//! Common code used to created quinn connections in the examples
2+
use std::{path::PathBuf, sync::Arc};
3+
24
use anyhow::{bail, Context, Result};
35
use quinn::crypto::rustls::{QuicClientConfig, QuicServerConfig};
4-
use std::{path::PathBuf, sync::Arc};
56
use tokio::fs;
67

78
pub const EXAMPLE_ALPN: &[u8] = b"n0/iroh/examples/bytes/0";

iroh-blobs/examples/fetch-fsm.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@
66
use std::net::SocketAddr;
77

88
use anyhow::{Context, Result};
9-
use iroh_io::ConcatenateSliceWriter;
10-
use tracing_subscriber::{prelude::*, EnvFilter};
11-
129
use iroh_blobs::{
1310
get::fsm::{AtInitial, ConnectedNext, EndBlobNext},
1411
hashseq::HashSeq,
1512
protocol::GetRequest,
1613
Hash,
1714
};
15+
use iroh_io::ConcatenateSliceWriter;
16+
use tracing_subscriber::{prelude::*, EnvFilter};
1817

1918
mod connect;
2019
use connect::{load_certs, make_client_endpoint};

iroh-blobs/examples/fetch-stream.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,21 @@
33
//! Since this example does not use [`iroh-net::Endpoint`], it does not do any holepunching, and so will only work locally or between two processes that have public IP addresses.
44
//!
55
//! Run the provide-bytes example first. It will give instructions on how to run this example properly.
6-
use std::net::SocketAddr;
6+
use std::{io, net::SocketAddr};
77

88
use anyhow::{Context, Result};
9-
use tracing_subscriber::{prelude::*, EnvFilter};
10-
11-
use std::io;
12-
139
use bao_tree::io::fsm::BaoContentItem;
1410
use bytes::Bytes;
1511
use futures_lite::{Stream, StreamExt};
16-
use genawaiter::sync::Co;
17-
use genawaiter::sync::Gen;
18-
use tokio::io::AsyncWriteExt;
19-
12+
use genawaiter::sync::{Co, Gen};
2013
use iroh_blobs::{
2114
get::fsm::{AtInitial, BlobContentNext, ConnectedNext, EndBlobNext},
2215
hashseq::HashSeq,
2316
protocol::GetRequest,
2417
Hash,
2518
};
19+
use tokio::io::AsyncWriteExt;
20+
use tracing_subscriber::{prelude::*, EnvFilter};
2621

2722
mod connect;
2823
use connect::{load_certs, make_client_endpoint};

iroh-blobs/examples/provide-bytes.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@
1010
//! cargo run --example provide-bytes collection
1111
//! To provide a collection (multiple blobs)
1212
use anyhow::Result;
13+
use iroh_blobs::{format::collection::Collection, util::local_pool::LocalPool, Hash};
1314
use tracing::warn;
1415
use tracing_subscriber::{prelude::*, EnvFilter};
1516

16-
use iroh_blobs::{format::collection::Collection, util::local_pool::LocalPool, Hash};
17-
1817
mod connect;
1918
use connect::{make_and_write_certs, make_server_endpoint, CERT_PATH};
2019

iroh-blobs/src/downloader/get.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
//!
33
//! [`Connection`]: iroh_net::endpoint::Connection
44
5-
use crate::{
6-
get::{db::get_to_db_in_steps, error::GetError},
7-
store::Store,
8-
};
95
use futures_lite::FutureExt;
106
use iroh_net::endpoint;
117

128
use super::{progress::BroadcastProgressSender, DownloadKind, FailureAction, GetStartFut, Getter};
9+
use crate::{
10+
get::{db::get_to_db_in_steps, error::GetError},
11+
store::Store,
12+
};
1313

1414
impl From<GetError> for FailureAction {
1515
fn from(e: GetError) -> Self {
@@ -74,8 +74,9 @@ impl super::NeedsConn<endpoint::Connection> for crate::get::db::GetStateNeedsCon
7474

7575
#[cfg(feature = "metrics")]
7676
fn track_metrics(res: &Result<crate::get::Stats, GetError>) {
77-
use crate::metrics::Metrics;
7877
use iroh_metrics::{inc, inc_by};
78+
79+
use crate::metrics::Metrics;
7980
match res {
8081
Ok(stats) => {
8182
let crate::get::Stats {

iroh-blobs/src/downloader/progress.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,12 @@ use std::{
99
use anyhow::anyhow;
1010
use parking_lot::Mutex;
1111

12+
use super::DownloadKind;
1213
use crate::{
1314
get::{db::DownloadProgress, progress::TransferState},
1415
util::progress::{AsyncChannelProgressSender, IdGenerator, ProgressSendError, ProgressSender},
1516
};
1617

17-
use super::DownloadKind;
18-
1918
/// The channel that can be used to subscribe to progress updates.
2019
pub type ProgressSubscriber = AsyncChannelProgressSender<DownloadProgress>;
2120

iroh-blobs/src/downloader/test.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
#![cfg(test)]
2-
use anyhow::anyhow;
32
use std::{
43
sync::atomic::AtomicUsize,
54
time::{Duration, Instant},
65
};
76

7+
use anyhow::anyhow;
88
use futures_util::future::FutureExt;
99
use iroh_net::key::SecretKey;
1010

11+
use super::*;
1112
use crate::{
1213
get::{
1314
db::BlobId,
@@ -19,8 +20,6 @@ use crate::{
1920
},
2021
};
2122

22-
use super::*;
23-
2423
mod dialer;
2524
mod getter;
2625

iroh-blobs/src/downloader/test/getter.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
use futures_lite::{future::Boxed as BoxFuture, FutureExt};
44
use parking_lot::RwLock;
55

6-
use crate::downloader;
7-
86
use super::*;
7+
use crate::downloader;
98

109
#[derive(Default, Clone, derive_more::Debug)]
1110
#[debug("TestingGetter")]

iroh-blobs/src/get.rs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,23 @@
1212
//! or you can choose to finish early.
1313
//!
1414
//! [iroh-net]: https://docs.rs/iroh-net
15-
use std::error::Error;
16-
use std::fmt::{self, Debug};
17-
use std::time::{Duration, Instant};
15+
use std::{
16+
error::Error,
17+
fmt::{self, Debug},
18+
time::{Duration, Instant},
19+
};
1820

19-
use crate::Hash;
2021
use anyhow::Result;
21-
use bao_tree::io::fsm::BaoContentItem;
22-
use bao_tree::ChunkNum;
22+
use bao_tree::{io::fsm::BaoContentItem, ChunkNum};
2323
use iroh_net::endpoint::{self, RecvStream, SendStream};
2424
use serde::{Deserialize, Serialize};
2525
use tracing::{debug, error};
2626

27-
use crate::protocol::RangeSpecSeq;
28-
use crate::util::io::{TrackingReader, TrackingWriter};
29-
use crate::IROH_BLOCK_SIZE;
27+
use crate::{
28+
protocol::RangeSpecSeq,
29+
util::io::{TrackingReader, TrackingWriter},
30+
Hash, IROH_BLOCK_SIZE,
31+
};
3032

3133
pub mod db;
3234
pub mod error;
@@ -59,13 +61,6 @@ impl Stats {
5961
pub mod fsm {
6062
use std::{io, result};
6163

62-
use crate::{
63-
protocol::{GetRequest, NonEmptyRequestRangeSpecIter, Request, MAX_MESSAGE_SIZE},
64-
store::BaoBatchWriter,
65-
};
66-
67-
use super::*;
68-
6964
use bao_tree::{
7065
io::fsm::{OutboardMut, ResponseDecoder, ResponseDecoderNext},
7166
BaoTree, ChunkRanges, TreeNode,
@@ -75,6 +70,12 @@ pub mod fsm {
7570
use iroh_net::endpoint::Connection;
7671
use tokio::io::AsyncWriteExt;
7772

73+
use super::*;
74+
use crate::{
75+
protocol::{GetRequest, NonEmptyRequestRangeSpecIter, Request, MAX_MESSAGE_SIZE},
76+
store::BaoBatchWriter,
77+
};
78+
7879
type WrappedRecvStream = TrackingReader<TokioStreamReader<RecvStream>>;
7980

8081
self_cell::self_cell! {

0 commit comments

Comments
 (0)