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 <divma@protonmail.com> Co-authored-by: Divma <26765164+divagant-martian@users.noreply.github.com>
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! {

iroh-blobs/src/get/db.rs

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,20 @@
11
//! Functions that use the iroh-blobs protocol in conjunction with a bao store.
22
3-
use std::future::Future;
4-
use std::io;
5-
use std::num::NonZeroU64;
6-
use std::pin::Pin;
3+
use std::{future::Future, io, num::NonZeroU64, pin::Pin};
74

5+
use anyhow::anyhow;
6+
use bao_tree::{ChunkNum, ChunkRanges};
87
use futures_lite::StreamExt;
98
use genawaiter::{
109
rc::{Co, Gen},
1110
GeneratorState,
1211
};
13-
use iroh_base::hash::Hash;
14-
use iroh_base::rpc::RpcError;
12+
use iroh_base::{hash::Hash, rpc::RpcError};
13+
use iroh_io::AsyncSliceReader;
1514
use iroh_net::endpoint::Connection;
1615
use serde::{Deserialize, Serialize};
1716
use tokio::sync::oneshot;
18-
19-
use crate::hashseq::parse_hash_seq;
20-
use crate::protocol::RangeSpec;
21-
use crate::store::BaoBatchWriter;
22-
use crate::store::BaoBlobSize;
23-
use crate::store::FallibleProgressBatchWriter;
17+
use tracing::trace;
2418

2519
use crate::{
2620
get::{
@@ -30,15 +24,15 @@ use crate::{
3024
progress::TransferState,
3125
Stats,
3226
},
33-
protocol::{GetRequest, RangeSpecSeq},
34-
store::{MapEntry, MapEntryMut, MapMut, Store as BaoStore},
27+
hashseq::parse_hash_seq,
28+
protocol::{GetRequest, RangeSpec, RangeSpecSeq},
29+
store::{
30+
BaoBatchWriter, BaoBlobSize, FallibleProgressBatchWriter, MapEntry, MapEntryMut, MapMut,
31+
Store as BaoStore,
32+
},
3533
util::progress::{IdGenerator, ProgressSender},
3634
BlobFormat, HashAndFormat,
3735
};
38-
use anyhow::anyhow;
39-
use bao_tree::{ChunkNum, ChunkRanges};
40-
use iroh_io::AsyncSliceReader;
41-
use tracing::trace;
4236

4337
type GetGenerator = Gen<Yield, (), Pin<Box<dyn Future<Output = Result<Stats, GetError>>>>>;
4438
type GetFuture = Pin<Box<dyn Future<Output = Result<Stats, GetError>> + 'static>>;

iroh-blobs/src/get/progress.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ use std::{collections::HashMap, num::NonZeroU64};
55
use serde::{Deserialize, Serialize};
66
use tracing::warn;
77

8-
use crate::{protocol::RangeSpec, store::BaoBlobSize, Hash};
9-
108
use super::db::{BlobId, DownloadProgress};
9+
use crate::{protocol::RangeSpec, store::BaoBlobSize, Hash};
1110

1211
/// The identifier for progress events.
1312
pub type ProgressId = u64;

iroh-blobs/src/get/request.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
//! Utilities for complex get requests.
22
use std::sync::Arc;
33

4-
use crate::{
5-
hashseq::HashSeq,
6-
protocol::{GetRequest, RangeSpecSeq},
7-
Hash, HashAndFormat,
8-
};
94
use bao_tree::{ChunkNum, ChunkRanges};
105
use bytes::Bytes;
116
use iroh_net::endpoint::Connection;
127
use rand::Rng;
138

149
use super::{fsm, Stats};
10+
use crate::{
11+
hashseq::HashSeq,
12+
protocol::{GetRequest, RangeSpecSeq},
13+
Hash, HashAndFormat,
14+
};
1515

1616
/// Get the claimed size of a blob from a peer.
1717
///

iroh-blobs/src/hashseq.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
//! traits related to collections of blobs
2-
use crate::Hash;
2+
use std::{fmt::Debug, io};
3+
34
use bytes::Bytes;
45
use iroh_io::{AsyncSliceReader, AsyncSliceReaderExt};
5-
use std::{fmt::Debug, io};
6+
7+
use crate::Hash;
68

79
/// A sequence of links, backed by a [`Bytes`] object.
810
#[derive(Debug, Clone, derive_more::Into)]

iroh-blobs/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ pub mod provider;
4040
pub mod store;
4141
pub mod util;
4242

43-
pub use crate::util::{Tag, TempTag};
43+
use bao_tree::BlockSize;
4444
pub use iroh_base::hash::{BlobFormat, Hash, HashAndFormat};
4545

46-
use bao_tree::BlockSize;
46+
pub use crate::util::{Tag, TempTag};
4747

4848
/// Block size used by iroh, 2^4*1024 = 16KiB
4949
pub const IROH_BLOCK_SIZE: BlockSize = BlockSize::from_chunk_log(4);

iroh-blobs/src/protocol/range_spec.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,10 +354,11 @@ impl<'a> Iterator for NonEmptyRequestRangeSpecIter<'a> {
354354
mod tests {
355355
use std::ops::Range;
356356

357-
use super::*;
358357
use iroh_test::{assert_eq_hex, hexdump::parse_hexdump};
359358
use proptest::prelude::*;
360359

360+
use super::*;
361+
361362
fn ranges(value_range: Range<u64>) -> impl Strategy<Value = ChunkRanges> {
362363
prop::collection::vec((value_range.clone(), value_range), 0..16).prop_map(|v| {
363364
let mut res = ChunkRanges::empty();

0 commit comments

Comments
 (0)