Skip to content
This repository was archived by the owner on Dec 18, 2023. It is now read-only.

Commit f6f44b3

Browse files
committed
fix: clippy
1 parent 430f3dd commit f6f44b3

File tree

9 files changed

+42
-55
lines changed

9 files changed

+42
-55
lines changed

iroh-api/src/api.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,9 @@ impl Api {
183183
) -> Result<BoxStream<'static, Result<(Cid, u64)>>> {
184184
let blocks = match entry {
185185
UnixfsEntry::File(f) => f.encode().await?.boxed(),
186-
UnixfsEntry::Directory(d) => d.encode(&DEFAULT_CODE),
186+
UnixfsEntry::Directory(d) => d.encode(DEFAULT_CODE),
187187
UnixfsEntry::Symlink(s) => Box::pin(async_stream::try_stream! {
188-
yield s.encode(&DEFAULT_CODE)?
188+
yield s.encode(DEFAULT_CODE)?
189189
}),
190190
UnixfsEntry::RawBlock(r) => Box::pin(async_stream::try_stream! {
191191
yield r.encode()?

iroh-bitswap/src/lib.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,21 +77,16 @@ pub struct Bitswap<S: Store> {
7777
_workers: Arc<Vec<JoinHandle<()>>>,
7878
}
7979

80-
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
80+
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
8181
enum PeerState {
8282
Connected(ConnectionId),
8383
Responsive(ConnectionId, ProtocolId),
8484
Unresponsive,
85+
#[default]
8586
Disconnected,
8687
DialFailure(Instant),
8788
}
8889

89-
impl Default for PeerState {
90-
fn default() -> Self {
91-
PeerState::Disconnected
92-
}
93-
}
94-
9590
impl PeerState {
9691
fn is_connected(self) -> bool {
9792
matches!(self, PeerState::Connected(_) | PeerState::Responsive(_, _))
@@ -496,10 +491,7 @@ impl<S: Store> NetworkBehaviour for Bitswap<S> {
496491
}
497492
}
498493
}
499-
HandlerEvent::Message {
500-
mut message,
501-
protocol,
502-
} => {
494+
HandlerEvent::Message { message, protocol } => {
503495
self.set_peer_state(&peer_id, PeerState::Responsive(connection, protocol));
504496
self.receive_message(peer_id, message);
505497
}

iroh-gateway/src/client.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,10 @@ impl<T: ContentLoader + std::marker::Unpin> Client<T> {
140140
) -> Result<Out, String> {
141141
info!("retrieve path metadata {}", path);
142142
if raw_format {
143-
return self
144-
.resolver
143+
self.resolver
145144
.resolve_raw(path)
146145
.await
147-
.map_err(|e| e.to_string());
146+
.map_err(|e| e.to_string())
148147
} else {
149148
self.resolver.resolve(path).await.map_err(|e| e.to_string())
150149
}

iroh-gateway/src/core.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ mod tests {
220220
}
221221

222222
let root_dir = dir_builder.build().unwrap();
223-
let mut parts = root_dir.encode(&DEFAULT_CODE);
223+
let mut parts = root_dir.encode(DEFAULT_CODE);
224224
while let Some(part) = parts.next().await {
225225
let (cid, bytes, links) = part.unwrap().into_parts();
226226
cids.push(cid);

iroh-resolver/tests/roundtrip.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ async fn build_testdir(
110110
/// a roundtrip test that converts a dir to an unixfs DAG and back
111111
async fn dir_roundtrip_test(dir: TestDir, hamt: bool) -> Result<bool> {
112112
let directory = build_directory("", &dir, hamt).await?;
113-
let stream = directory.encode(&DEFAULT_CODE);
113+
let stream = directory.encode(DEFAULT_CODE);
114114
let (root, resolver) = stream_to_resolver(stream).await?;
115115
let stream =
116116
resolver.resolve_recursive_with_paths(iroh_resolver::resolver::Path::from_cid(root));
@@ -155,7 +155,7 @@ async fn symlink_roundtrip_test() -> Result<()> {
155155
let target = "../../bar.txt";
156156
builder.target(target);
157157
let sym = builder.build().await?;
158-
let block = sym.encode(&DEFAULT_CODE)?;
158+
let block = sym.encode(DEFAULT_CODE)?;
159159
let stream = async_stream::try_stream! {
160160
yield block;
161161
};

iroh-share/src/sender.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ impl Sender {
6666
let p2p_rpc = p2p.rpc().try_p2p()?;
6767
let store = p2p.rpc().try_store()?;
6868
let (root, num_parts) = {
69-
let parts = root_dir.encode(&DEFAULT_CODE);
69+
let parts = root_dir.encode(DEFAULT_CODE);
7070
tokio::pin!(parts);
7171
let mut num_parts = 0;
7272
let mut root_cid = None;

iroh-unixfs/src/balanced_tree.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ impl TreeBuilder {
4040
chunks: impl Stream<Item = std::io::Result<Bytes>> + Send,
4141
) -> impl Stream<Item = Result<Block>> {
4242
match self {
43-
TreeBuilder::Balanced { degree, code } => {
44-
stream_balanced_tree(chunks, *degree, code.clone())
45-
}
43+
TreeBuilder::Balanced { degree, code } => stream_balanced_tree(chunks, *degree, *code),
4644
}
4745
}
4846
}
@@ -54,10 +52,10 @@ pub struct LinkInfo {
5452
}
5553

5654
impl LinkInfo {
57-
pub fn new(raw_data_len: u64, encoded_len: u64) -> LinkInfo{
55+
pub fn new(raw_data_len: u64, encoded_len: u64) -> LinkInfo {
5856
LinkInfo {
5957
raw_data_len,
60-
encoded_len
58+
encoded_len,
6159
}
6260
}
6361
}
@@ -98,7 +96,7 @@ fn stream_balanced_tree(
9896
let in_stream = in_stream.err_into::<anyhow::Error>().map(|chunk| {
9997
let code = code.clone();
10098
tokio::task::spawn_blocking(move || {
101-
chunk.and_then(|chunk| TreeNode::Leaf(chunk).encode(&code))
99+
chunk.and_then(|chunk| TreeNode::Leaf(chunk).encode(code))
102100
}).err_into::<anyhow::Error>()
103101
}).buffered(hash_par).map(|x| x.and_then(|x| x));
104102

@@ -125,7 +123,7 @@ fn stream_balanced_tree(
125123

126124
// create node, keeping the cid
127125
let links = std::mem::replace(&mut tree[i], Vec::with_capacity(degree));
128-
let (block, link_info) = TreeNode::Stem(links).encode(&code)?;
126+
let (block, link_info) = TreeNode::Stem(links).encode(code)?;
129127
let cid = *block.cid();
130128
yield block;
131129

@@ -154,7 +152,7 @@ fn stream_balanced_tree(
154152
// since all the stem nodes are able to receive links
155153
// we don't have to worry about "overflow"
156154
while let Some(links) = tree.pop_front() {
157-
let (block, link_info) = TreeNode::Stem(links).encode(&code)?;
155+
let (block, link_info) = TreeNode::Stem(links).encode(code)?;
158156
let cid = *block.cid();
159157
yield block;
160158

@@ -215,7 +213,7 @@ pub enum TreeNode {
215213
}
216214

217215
impl TreeNode {
218-
pub fn encode(self, code: &multihash::Code) -> Result<(Block, LinkInfo)> {
216+
pub fn encode(self, code: multihash::Code) -> Result<(Block, LinkInfo)> {
219217
match self {
220218
TreeNode::Leaf(bytes) => {
221219
let len = bytes.len();
@@ -271,15 +269,15 @@ mod tests {
271269
if num_chunks / degree == 0 {
272270
let chunk = chunks.next().await.unwrap().unwrap();
273271
let leaf = TreeNode::Leaf(chunk);
274-
let (block, _) = leaf.encode(&multihash::Code::Sha2_256).unwrap();
272+
let (block, _) = leaf.encode(multihash::Code::Sha2_256).unwrap();
275273
tree[0].push(block);
276274
return tree;
277275
}
278276

279277
while let Some(chunk) = chunks.next().await {
280278
let chunk = chunk.unwrap();
281279
let leaf = TreeNode::Leaf(chunk);
282-
let (block, link_info) = leaf.encode(&multihash::Code::Sha2_256).unwrap();
280+
let (block, link_info) = leaf.encode(multihash::Code::Sha2_256).unwrap();
283281
links[0].push((*block.cid(), link_info));
284282
tree[0].push(block);
285283
}
@@ -291,7 +289,7 @@ mod tests {
291289
let mut links_layer = Vec::with_capacity(count);
292290
for links in prev_layer.chunks(degree) {
293291
let stem = TreeNode::Stem(links.to_vec());
294-
let (block, link_info) = stem.encode(&multihash::Code::Sha2_256).unwrap();
292+
let (block, link_info) = stem.encode(multihash::Code::Sha2_256).unwrap();
295293
links_layer.push((*block.cid(), link_info));
296294
tree_layer.push(block);
297295
}
@@ -355,13 +353,13 @@ mod tests {
355353

356354
fn make_leaf(data: usize) -> (Block, LinkInfo) {
357355
TreeNode::Leaf(BytesMut::from(&data.to_be_bytes()[..]).freeze())
358-
.encode(&multihash::Code::Sha2_256)
356+
.encode(multihash::Code::Sha2_256)
359357
.unwrap()
360358
}
361359

362360
fn make_stem(links: Vec<(Cid, LinkInfo)>) -> (Block, LinkInfo) {
363361
TreeNode::Stem(links)
364-
.encode(&multihash::Code::Sha2_256)
362+
.encode(multihash::Code::Sha2_256)
365363
.unwrap()
366364
}
367365

iroh-unixfs/src/builder.rs

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ impl Directory {
9393
Directory::single("".into(), Entry::Directory(self))
9494
}
9595

96-
pub async fn encode_root(self, code: &multihash::Code) -> Result<Block> {
96+
pub async fn encode_root(self, code: multihash::Code) -> Result<Block> {
9797
let mut current = None;
9898
let parts = self.encode(code);
9999
tokio::pin!(parts);
@@ -105,7 +105,7 @@ impl Directory {
105105
current.expect("must not be empty")
106106
}
107107

108-
pub fn encode<'a>(self, code: &multihash::Code) -> BoxStream<'a, Result<Block>> {
108+
pub fn encode<'a>(self, code: multihash::Code) -> BoxStream<'a, Result<Block>> {
109109
match self {
110110
Directory::Basic(basic) => basic.encode(code),
111111
Directory::Hamt(hamt) => hamt.encode(code),
@@ -114,13 +114,12 @@ impl Directory {
114114
}
115115

116116
impl BasicDirectory {
117-
pub fn encode<'a>(self, code: &multihash::Code) -> BoxStream<'a, Result<Block>> {
118-
let code = code.clone();
117+
pub fn encode<'a>(self, code: multihash::Code) -> BoxStream<'a, Result<Block>> {
119118
async_stream::try_stream! {
120119
let mut links = Vec::new();
121120
for entry in self.entries {
122121
let name = entry.name().to_string();
123-
let parts = entry.encode(&code).await?;
122+
let parts = entry.encode(code).await?;
124123
tokio::pin!(parts);
125124
let mut root = None;
126125
let mut size = 0u64;
@@ -145,14 +144,14 @@ impl BasicDirectory {
145144
};
146145
let outer = encode_unixfs_pb(&inner, links)?;
147146
let node = UnixfsNode::Directory(Node { outer, inner });
148-
yield node.encode(&code)?;
147+
yield node.encode(code)?;
149148
}
150149
.boxed()
151150
}
152151
}
153152

154153
impl HamtDirectory {
155-
pub fn encode<'a>(self, code: &multihash::Code) -> BoxStream<'a, Result<Block>> {
154+
pub fn encode<'a>(self, code: multihash::Code) -> BoxStream<'a, Result<Block>> {
156155
self.hamt.encode(code)
157156
}
158157
}
@@ -264,7 +263,7 @@ impl Symlink {
264263
&self.name
265264
}
266265

267-
pub fn encode(self, code: &multihash::Code) -> Result<Block> {
266+
pub fn encode(self, code: multihash::Code) -> Result<Block> {
268267
let target = self
269268
.target
270269
.to_str()
@@ -463,7 +462,7 @@ impl Entry {
463462
}
464463
}
465464

466-
pub async fn encode(self, code: &multihash::Code) -> Result<BoxStream<'static, Result<Block>>> {
465+
pub async fn encode(self, code: multihash::Code) -> Result<BoxStream<'static, Result<Block>>> {
467466
Ok(match self {
468467
Entry::File(f) => f.encode().await?.boxed(),
469468
Entry::Directory(d) => d.encode(code),
@@ -595,7 +594,7 @@ impl DirectoryBuilder {
595594

596595
pub async fn add_path(self, path: impl Into<PathBuf>) -> Result<Self> {
597596
let chunker = self.chunker.clone();
598-
let degree = self.degree.clone();
597+
let degree = self.degree;
599598
Ok(self.add_entries(
600599
make_entries_from_path(path, chunker, degree)
601600
.await?
@@ -680,8 +679,7 @@ impl HamtNode {
680679
}
681680
}
682681

683-
pub fn encode<'a>(self, code: &multihash::Code) -> BoxStream<'a, Result<Block>> {
684-
let code = code.clone();
682+
pub fn encode<'a>(self, code: multihash::Code) -> BoxStream<'a, Result<Block>> {
685683
match self {
686684
Self::Branch(tree) => {
687685
async_stream::try_stream! {
@@ -690,7 +688,7 @@ impl HamtNode {
690688
for (prefix, node) in tree {
691689
let name = format!("{:02X}{}", prefix, node.name());
692690
bitfield.set_bit(prefix);
693-
let blocks = node.encode(&code);
691+
let blocks = node.encode(code);
694692
let mut root = None;
695693
tokio::pin!(blocks);
696694
while let Some(block) = blocks.next().await {
@@ -715,11 +713,11 @@ impl HamtNode {
715713
// it does not really matter what enum variant we choose here as long as
716714
// it is not raw. The type of the node will be HamtShard from above.
717715
let node = UnixfsNode::Directory(crate::unixfs::Node { outer, inner });
718-
yield node.encode(&code)?;
716+
yield node.encode(code)?;
719717
}
720718
.boxed()
721719
}
722-
Self::Leaf(HamtLeaf(_hash, entry)) => async move { entry.encode(&code).await }
720+
Self::Leaf(HamtLeaf(_hash, entry)) => async move { entry.encode(code).await }
723721
.try_flatten_stream()
724722
.boxed(),
725723
}
@@ -862,12 +860,12 @@ mod tests {
862860
let mut baz = SymlinkBuilder::new("baz.txt");
863861
baz.target("bat.txt");
864862
let baz = baz.build().await?;
865-
baz.encode(&multihash::Code::Sha2_256)?
863+
baz.encode(multihash::Code::Sha2_256)?
866864
};
867865

868866
let dir = dir.add_file(bar).add_symlink(baz).build()?;
869867

870-
let dir_block = dir.encode_root(&multihash::Code::Sha2_256).await?;
868+
let dir_block = dir.encode_root(multihash::Code::Sha2_256).await?;
871869
let decoded_dir = UnixfsNode::decode(dir_block.cid(), dir_block.data().clone())?;
872870

873871
let links = decoded_dir.links().collect::<Result<Vec<_>>>().unwrap();
@@ -919,12 +917,12 @@ mod tests {
919917
let mut baz = SymlinkBuilder::new("baz.txt");
920918
baz.target("bat.txt");
921919
let baz = baz.build().await?;
922-
baz.encode(&multihash::Code::Sha2_256)?
920+
baz.encode(multihash::Code::Sha2_256)?
923921
};
924922

925923
let dir = dir.add_file(bar).add_symlink(baz).build()?;
926924

927-
let dir_block = dir.encode_root(&multihash::Code::Sha2_256).await?;
925+
let dir_block = dir.encode_root(multihash::Code::Sha2_256).await?;
928926
let decoded_dir = UnixfsNode::decode(dir_block.cid(), dir_block.data().clone())?;
929927

930928
let links = decoded_dir.links().collect::<Result<Vec<_>>>().unwrap();
@@ -997,7 +995,7 @@ mod tests {
997995

998996
let dir = dir.add_file(bar).add_file(baz).build()?;
999997

1000-
let dir_block = dir.encode_root(&multihash::Code::Sha2_256).await?;
998+
let dir_block = dir.encode_root(multihash::Code::Sha2_256).await?;
1001999
let decoded_dir = UnixfsNode::decode(dir_block.cid(), dir_block.data().clone())?;
10021000

10031001
let links = decoded_dir.links().collect::<Result<Vec<_>>>().unwrap();

iroh-unixfs/src/unixfs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ impl UnixfsNode {
179179
}
180180
}
181181

182-
pub fn encode(&self, code: &multihash::Code) -> Result<Block> {
182+
pub fn encode(&self, code: multihash::Code) -> Result<Block> {
183183
let res = match self {
184184
UnixfsNode::Raw(data) => {
185185
let out = data.clone();

0 commit comments

Comments
 (0)