diff --git a/http/src/v0/block.rs b/http/src/v0/block.rs index bae8d302..b3b6850a 100644 --- a/http/src/v0/block.rs +++ b/http/src/v0/block.rs @@ -75,7 +75,7 @@ async fn put_query( 1 => Version::V1, _ => return Err(StringError::from("invalid cid version").into()), }; - let mut buf = form + let buf = form .next() .await .ok_or(InvalidMultipartFormData)? @@ -84,7 +84,7 @@ async fn put_query( .await .ok_or(InvalidMultipartFormData)? .map_err(|_| InvalidMultipartFormData)?; - let data = buf.to_bytes().as_ref().to_vec().into_boxed_slice(); + let data = Box::from(buf.bytes()); let digest = hasher(&data); let cid = Cid::new(version, format, digest).map_err(StringError::from)?; let response = PutResponse { @@ -163,19 +163,10 @@ async fn rm_query( hash: cid.to_string(), error: "".to_string(), }, - Err((cid, e)) => { - if force { - RmResponse { - hash: cid.to_string(), - error: "".to_string(), - } - } else { - RmResponse { - hash: cid.to_string(), - error: e.to_string(), - } - } - } + Err((cid, e)) => RmResponse { + hash: cid.to_string(), + error: if force { "".to_string() } else { e.to_string() }, + }, }) .map(|response: RmResponse| serde_json::to_string(&response)) .map(move |result| match result { diff --git a/http/src/v0/dag.rs b/http/src/v0/dag.rs index b6e3bb44..b15e56cc 100644 --- a/http/src/v0/dag.rs +++ b/http/src/v0/dag.rs @@ -32,7 +32,7 @@ async fn put_query( "sha3-512" => (Sha3_512::digest as fn(&[u8]) -> Multihash, false), _ => return Err(StringError::from("unknown hash").into()), }; - let mut buf = form + let buf = form .next() .await .ok_or(InvalidMultipartFormData)? @@ -41,7 +41,7 @@ async fn put_query( .await .ok_or(InvalidMultipartFormData)? .map_err(|_| InvalidMultipartFormData)?; - let data = buf.to_bytes().as_ref().to_vec().into_boxed_slice(); + let data = Box::from(buf.bytes()); let digest = hasher(&data); let cid = if v0_fmt && v0_hash { // this is quite ugly way but apparently js-ipfs generates a v0 cid for this combination diff --git a/http/src/v0/pubsub.rs b/http/src/v0/pubsub.rs index 3954c9b0..cf3e722d 100644 --- a/http/src/v0/pubsub.rs +++ b/http/src/v0/pubsub.rs @@ -232,7 +232,7 @@ async fn shovel( } }; - if tx.send(next.clone()).is_err() { + if tx.send(next).is_err() { // currently no more subscribers unsubscribed = false; break; @@ -492,7 +492,7 @@ impl<'a> Iterator for QueryAsRawPartsParser<'a> { let mut split2 = self.input.splitn(2, |&b| b == b'&'); let sequence = split2.next().expect("splitn will always return first"); - self.input = split2.next().unwrap_or(&[][..]); + self.input = split2.next().unwrap_or_default(); if sequence.is_empty() { continue; @@ -500,7 +500,7 @@ impl<'a> Iterator for QueryAsRawPartsParser<'a> { let mut split2 = sequence.splitn(2, |&b| b == b'='); let name = split2.next().expect("splitn will always return first"); - let value = split2.next().unwrap_or(&[][..]); + let value = split2.next().unwrap_or_default(); // original implementation calls percent_decode for both arguments into lossy Cow return Some((name, value)); } diff --git a/http/src/v0/refs/path.rs b/http/src/v0/refs/path.rs index 2064bfdd..99a56e3b 100644 --- a/http/src/v0/refs/path.rs +++ b/http/src/v0/refs/path.rs @@ -133,7 +133,7 @@ impl IpfsPath { // FIXME: this would require the iterator to be peekable in addition. return Ok(WalkSuccess::Link(key, cid)); } - Ipld::Map(mut m) if m.contains_key(&key) => { + Ipld::Map(mut m) => { if let Some(ipld) = m.remove(&key) { ipld } else {