Cargo clippy: fix the majority of errors
This commit is contained in:
parent
871d927596
commit
6968a4e449
19 changed files with 69 additions and 91 deletions
|
|
@ -50,7 +50,7 @@ pub async fn read_metainfo_from_peer_receiver<A: Stream<Item = SocketAddr> + Unp
|
|||
BlockingSpawner::new(true),
|
||||
)
|
||||
.await
|
||||
.with_context(|| format!("error reading metainfo from {}", addr));
|
||||
.with_context(|| format!("error reading metainfo from {addr}"));
|
||||
drop(token);
|
||||
ret
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,12 +34,8 @@ pub fn update_hash_from_file<Sha1: ISha1>(
|
|||
let mut read = 0;
|
||||
while bytes_to_read > 0 {
|
||||
let chunk = std::cmp::min(buf.len(), bytes_to_read);
|
||||
file.read_exact(&mut buf[..chunk]).with_context(|| {
|
||||
format!(
|
||||
"failed reading chunk of size {}, read so far {}",
|
||||
chunk, read
|
||||
)
|
||||
})?;
|
||||
file.read_exact(&mut buf[..chunk])
|
||||
.with_context(|| format!("failed reading chunk of size {chunk}, read so far {read}"))?;
|
||||
bytes_to_read -= chunk;
|
||||
read += chunk;
|
||||
hash.update(&buf[..chunk]);
|
||||
|
|
@ -93,7 +89,7 @@ impl<'a, Sha1Impl: ISha1> FileOps<'a, Sha1Impl> {
|
|||
self.len - self.processed_bytes
|
||||
}
|
||||
fn mark_processed_bytes(&mut self, bytes: u64) {
|
||||
self.processed_bytes += bytes as u64
|
||||
self.processed_bytes += bytes
|
||||
}
|
||||
}
|
||||
let mut file_iterator = self
|
||||
|
|
@ -247,16 +243,12 @@ impl<'a, Sha1Impl: ISha1> FileOps<'a, Sha1Impl> {
|
|||
file_g
|
||||
.seek(SeekFrom::Start(absolute_offset))
|
||||
.with_context(|| {
|
||||
format!(
|
||||
"error seeking to {}, file id: {}",
|
||||
absolute_offset, file_idx
|
||||
)
|
||||
format!("error seeking to {absolute_offset}, file id: {file_idx}")
|
||||
})?;
|
||||
update_hash_from_file(&mut file_g, &mut h, &mut buf, to_read_in_file).with_context(
|
||||
|| {
|
||||
format!(
|
||||
"error reading {} bytes, file_id: {} (\"{:?}\")",
|
||||
to_read_in_file, file_idx, name
|
||||
"error reading {to_read_in_file} bytes, file_id: {file_idx} (\"{name:?}\")"
|
||||
)
|
||||
},
|
||||
)?;
|
||||
|
|
@ -315,18 +307,12 @@ impl<'a, Sha1Impl: ISha1> FileOps<'a, Sha1Impl> {
|
|||
file_g
|
||||
.seek(SeekFrom::Start(absolute_offset))
|
||||
.with_context(|| {
|
||||
format!(
|
||||
"error seeking to {}, file id: {}",
|
||||
absolute_offset, file_idx
|
||||
)
|
||||
format!("error seeking to {absolute_offset}, file id: {file_idx}")
|
||||
})?;
|
||||
file_g
|
||||
.read_exact(&mut buf[..to_read_in_file])
|
||||
.with_context(|| {
|
||||
format!(
|
||||
"error reading {} bytes, file_id: {}",
|
||||
file_idx, to_read_in_file
|
||||
)
|
||||
format!("error reading {file_idx} bytes, file_id: {to_read_in_file}")
|
||||
})?;
|
||||
|
||||
buf = &mut buf[to_read_in_file..];
|
||||
|
|
@ -376,14 +362,11 @@ impl<'a, Sha1Impl: ISha1> FileOps<'a, Sha1Impl> {
|
|||
file_g
|
||||
.seek(SeekFrom::Start(absolute_offset))
|
||||
.with_context(|| {
|
||||
format!(
|
||||
"error seeking to {} in file {} (\"{:?}\")",
|
||||
absolute_offset, file_idx, name
|
||||
)
|
||||
format!("error seeking to {absolute_offset} in file {file_idx} (\"{name:?}\")")
|
||||
})?;
|
||||
file_g
|
||||
.write_all(&buf[..to_write])
|
||||
.with_context(|| format!("error writing to file {} (\"{:?}\")", file_idx, name))?;
|
||||
.with_context(|| format!("error writing to file {file_idx} (\"{name:?}\")"))?;
|
||||
buf = &buf[to_write..];
|
||||
if buf.is_empty() {
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -15,12 +15,10 @@ async fn check_response(r: reqwest::Response) -> anyhow::Result<reqwest::Respons
|
|||
}
|
||||
let status = r.status();
|
||||
let url = r.url().clone();
|
||||
let body = r.text().await.with_context(|| {
|
||||
format!(
|
||||
"cannot read response body for request to {} ({})",
|
||||
url, status,
|
||||
)
|
||||
})?;
|
||||
let body = r
|
||||
.text()
|
||||
.await
|
||||
.with_context(|| format!("cannot read response body for request to {url} ({status})"))?;
|
||||
anyhow::bail!("{} -> {}: {}", url, status, body)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -110,7 +110,7 @@ impl HandlerLocked {
|
|||
anyhow::bail!("already received piece {}", index);
|
||||
}
|
||||
let offset_end = offset + size;
|
||||
(&mut self.buffer[offset..offset_end]).copy_from_slice(data);
|
||||
self.buffer[offset..offset_end].copy_from_slice(data);
|
||||
self.received_pieces[index as usize] = true;
|
||||
|
||||
if self.received_pieces.iter().all(|p| *p) {
|
||||
|
|
|
|||
|
|
@ -72,14 +72,14 @@ pub struct Session {
|
|||
async fn torrent_from_url(url: &str) -> anyhow::Result<TorrentMetaV1Owned> {
|
||||
let response = reqwest::get(url)
|
||||
.await
|
||||
.with_context(|| format!("error downloading torrent metadata from {}", url))?;
|
||||
.with_context(|| format!("error downloading torrent metadata from {url}"))?;
|
||||
if !response.status().is_success() {
|
||||
anyhow::bail!("GET {} returned {}", url, response.status())
|
||||
}
|
||||
let b = response
|
||||
.bytes()
|
||||
.await
|
||||
.with_context(|| format!("error reading repsonse body from {}", url))?;
|
||||
.with_context(|| format!("error reading repsonse body from {url}"))?;
|
||||
torrent_from_bytes(&b).context("error decoding torrent")
|
||||
}
|
||||
|
||||
|
|
@ -91,9 +91,9 @@ fn torrent_from_file(filename: &str) -> anyhow::Result<TorrentMetaV1Owned> {
|
|||
.context("error reading stdin")?;
|
||||
} else {
|
||||
File::open(filename)
|
||||
.with_context(|| format!("error opening {}", filename))?
|
||||
.with_context(|| format!("error opening {filename}"))?
|
||||
.read_to_end(&mut buf)
|
||||
.with_context(|| format!("error reading {}", filename))?;
|
||||
.with_context(|| format!("error reading {filename}"))?;
|
||||
}
|
||||
torrent_from_bytes(&buf).context("error decoding torrent")
|
||||
}
|
||||
|
|
@ -107,7 +107,7 @@ fn compute_only_files<ByteBuf: AsRef<[u8]>>(
|
|||
for (idx, (filename, _)) in torrent.iter_filenames_and_lengths()?.enumerate() {
|
||||
let full_path = filename
|
||||
.to_pathbuf()
|
||||
.with_context(|| format!("filename of file {} is not valid utf8", idx))?;
|
||||
.with_context(|| format!("filename of file {idx} is not valid utf8"))?;
|
||||
if filename_re.is_match(full_path.to_str().unwrap()) {
|
||||
only_files.push(idx);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -116,7 +116,7 @@ impl TorrentManagerHandle {
|
|||
pub fn add_tracker(&self, url: Url) -> bool {
|
||||
let mgr = self.manager.clone();
|
||||
if mgr.trackers.lock().insert(url.clone()) {
|
||||
spawn(format!("tracker monitor {}", url), async move {
|
||||
spawn(format!("tracker monitor {url}"), async move {
|
||||
mgr.single_tracker_monitor(url).await
|
||||
});
|
||||
true
|
||||
|
|
|
|||
|
|
@ -723,7 +723,7 @@ impl PeerHandler {
|
|||
}
|
||||
|
||||
fn on_bitfield(&self, handle: PeerHandle, bitfield: ByteString) -> anyhow::Result<()> {
|
||||
if bitfield.len() != self.state.lengths.piece_bitfield_bytes() as usize {
|
||||
if bitfield.len() != self.state.lengths.piece_bitfield_bytes() {
|
||||
anyhow::bail!(
|
||||
"dropping {} as its bitfield has unexpected size. Got {}, expected {}",
|
||||
handle,
|
||||
|
|
@ -754,7 +754,7 @@ impl PeerHandler {
|
|||
|
||||
// Additional spawn per peer, not good.
|
||||
spawn(
|
||||
format!("peer_chunk_requester({})", handle),
|
||||
format!("peer_chunk_requester({handle})"),
|
||||
self.clone().task_peer_chunk_requester(handle),
|
||||
);
|
||||
Ok(())
|
||||
|
|
@ -984,7 +984,7 @@ impl PeerHandler {
|
|||
.state
|
||||
.file_ops()
|
||||
.check_piece(handle, chunk_info.piece_index, &chunk_info)
|
||||
.with_context(|| format!("error checking piece={}", index))?
|
||||
.with_context(|| format!("error checking piece={index}"))?
|
||||
{
|
||||
true => {
|
||||
let piece_len =
|
||||
|
|
@ -1036,7 +1036,7 @@ impl PeerHandler {
|
|||
};
|
||||
Ok::<_, anyhow::Error>(())
|
||||
})
|
||||
.with_context(|| format!("error processing received chunk {:?}", chunk_info))?;
|
||||
.with_context(|| format!("error processing received chunk {chunk_info:?}"))?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -127,7 +127,7 @@ where
|
|||
where
|
||||
E: serde::de::Error,
|
||||
{
|
||||
IpAddr::from_str(v).map_err(|e| E::custom(format!("cannot parse ip: {}", e)))
|
||||
IpAddr::from_str(v).map_err(|e| E::custom(format!("cannot parse ip: {e}")))
|
||||
}
|
||||
}
|
||||
de.deserialize_str(Visitor {})
|
||||
|
|
@ -185,16 +185,16 @@ impl TrackerRequest {
|
|||
write!(s, "&compact={}", if self.compact { 1 } else { 0 }).unwrap();
|
||||
write!(s, "&no_peer_id={}", if self.no_peer_id { 1 } else { 0 }).unwrap();
|
||||
if let Some(ip) = &self.ip {
|
||||
write!(s, "&ip={}", ip).unwrap();
|
||||
write!(s, "&ip={ip}").unwrap();
|
||||
}
|
||||
if let Some(numwant) = &self.numwant {
|
||||
write!(s, "&numwant={}", numwant).unwrap();
|
||||
write!(s, "&numwant={numwant}").unwrap();
|
||||
}
|
||||
if let Some(key) = &self.key {
|
||||
write!(s, "&key={}", key).unwrap();
|
||||
write!(s, "&key={key}").unwrap();
|
||||
}
|
||||
if let Some(trackerid) = &self.trackerid {
|
||||
write!(s, "&trackerid={}", trackerid).unwrap();
|
||||
write!(s, "&trackerid={trackerid}").unwrap();
|
||||
}
|
||||
s
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue