Skip to content
This repository was archived by the owner on Oct 23, 2022. It is now read-only.

Commit 0a0d59a

Browse files
author
Joonas Koivunen
committed
refactor: clippy, fmt, shorter naming
1 parent 5e0b670 commit 0a0d59a

File tree

3 files changed

+14
-17
lines changed

3 files changed

+14
-17
lines changed

http/src/v0/refs.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use serde::Serialize;
88
use std::borrow::Cow;
99
use std::collections::VecDeque;
1010
use std::convert::TryFrom;
11-
use std::fmt;
1211
use warp::{Filter, Rejection, Reply};
1312

1413
mod options;
@@ -78,11 +77,11 @@ async fn refs_inner<T: IpfsTypes>(
7877
}
7978
Err(e) => serde_json::to_string(&Edge {
8079
ok: "".into(),
81-
err: e.to_string().into(),
80+
err: e.into(),
8281
}),
8382
};
8483

85-
let res = match res {
84+
match res {
8685
Ok(mut s) => {
8786
s.push('\n');
8887
Ok(s.into_bytes())
@@ -91,9 +90,7 @@ async fn refs_inner<T: IpfsTypes>(
9190
log::error!("edge serialization failed: {}", e);
9291
Err(HandledErr)
9392
}
94-
};
95-
96-
res
93+
}
9794
});
9895

9996
// Note: Unshared has the unsafe impl Sync which sadly is needed.
@@ -114,7 +111,7 @@ fn refs_options() -> impl Filter<Extract = (RefsOptions,), Error = Rejection> +
114111
warp::filters::query::raw().and_then(|q: String| {
115112
let res = RefsOptions::try_from(q.as_str())
116113
.map_err(StringError::from)
117-
.map_err(|e| warp::reject::custom(e));
114+
.map_err(warp::reject::custom);
118115

119116
futures::future::ready(res)
120117
})
@@ -325,7 +322,7 @@ fn dagpb_links(ipld: Ipld) -> Vec<(Option<String>, Cid)> {
325322
),
326323
};
327324

328-
return Some((name, link));
325+
Some((name, link))
329326
}
330327
x => panic!(
331328
"Expected dag-pb2ipld \"Links[{}]\" to be a map, got: {:?}",

http/src/v0/refs/options.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,16 @@ impl RefsOptions {
3838
}
3939

4040
#[derive(Debug)]
41-
pub enum RefOptionsParseError<'a> {
41+
pub enum ParseError<'a> {
4242
DuplicateField(Cow<'a, str>),
4343
MissingArg,
4444
InvalidNumber(Cow<'a, str>, Cow<'a, str>),
4545
InvalidBoolean(Cow<'a, str>, Cow<'a, str>),
4646
}
4747

48-
impl<'a> fmt::Display for RefOptionsParseError<'a> {
48+
impl<'a> fmt::Display for ParseError<'a> {
4949
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
50-
use RefOptionsParseError::*;
50+
use ParseError::*;
5151
match *self {
5252
DuplicateField(ref s) => write!(fmt, "field {:?} was duplicated", *s),
5353
MissingArg => write!(fmt, "required field \"arg\" missing"),
@@ -57,13 +57,13 @@ impl<'a> fmt::Display for RefOptionsParseError<'a> {
5757
}
5858
}
5959

60-
impl<'a> std::error::Error for RefOptionsParseError<'a> {}
60+
impl<'a> std::error::Error for ParseError<'a> {}
6161

6262
impl<'a> TryFrom<&'a str> for RefsOptions {
63-
type Error = RefOptionsParseError<'a>;
63+
type Error = ParseError<'a>;
6464

6565
fn try_from(q: &'a str) -> Result<Self, Self::Error> {
66-
use RefOptionsParseError::*;
66+
use ParseError::*;
6767

6868
// TODO: check how go-ipfs handles duplicate parameters for non-Vec fields
6969
//

http/src/v0/refs/path.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ impl TryFrom<&str> for IpfsPath {
6666
}
6767
Some(x) => {
6868
/* maybe didn't start with /ipfs/, need to check second */
69-
if let Some(_) = split.next() {
69+
if split.next().is_some() {
7070
// x/ipfs/_
7171
return Err(PathError::InvalidPath);
7272
}
@@ -110,7 +110,7 @@ impl IpfsPath {
110110
if self.len() == 0 {
111111
return Ok(WalkSuccess::EmptyPath(ipld));
112112
}
113-
while let Some(key) = self.next() {
113+
for key in self {
114114
if current.codec() == cid::Codec::DagProtobuf {
115115
return walk_dagpb(ipld, key);
116116
}
@@ -248,7 +248,7 @@ fn walk_dagpb(ipld: Ipld, key: String) -> Result<WalkSuccess, WalkFailed> {
248248
None => panic!("Expected dag-pb2ipld \"Links[{}]/Hash\" to exist", index),
249249
};
250250

251-
return Ok(WalkSuccess::Link(key, link));
251+
Ok(WalkSuccess::Link(key, link))
252252
}
253253
x => panic!(
254254
"Expected dag-pb2ipld \"Links[{}]\" to be a Map, was: {:?}",

0 commit comments

Comments
 (0)