Skip to content

Commit

Permalink
make clippy happy
Browse files Browse the repository at this point in the history
  • Loading branch information
Arqu committed Oct 11, 2022
1 parent 9c65f61 commit a3ab39b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 25 deletions.
8 changes: 3 additions & 5 deletions iroh-gateway/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,17 @@ impl GatewayError {
impl IntoResponse for GatewayError {
fn into_response(self) -> Response {
match self.method {
Some(http::Method::HEAD) => {
return (self.status_code).into_response();
}
Some(http::Method::HEAD) => (self.status_code).into_response(),
_ => {
let body = axum::Json(json!({
"code": self.status_code.as_u16(),
"success": false,
"message": self.message,
"trace_id": self.trace_id,
}));
return (self.status_code, body).into_response();
(self.status_code, body).into_response()
}
};
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion iroh-gateway/src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ pub async fn get_handler<T: ContentLoader + std::marker::Unpin>(
.map_err(|e| error(StatusCode::BAD_REQUEST, &e, &state))?;
let resolved_cid = resolved_path.root();

if handle_only_if_cached(&request_headers, &state, &resolved_cid).await? {
if handle_only_if_cached(&request_headers, &state, resolved_cid).await? {
return response(StatusCode::OK, Body::empty(), HeaderMap::new());
}

Expand Down
15 changes: 4 additions & 11 deletions iroh-gateway/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,22 +91,15 @@ pub fn get_response_format(
) -> Result<ResponseFormat, String> {
if let Some(format) = query_format {
if !format.is_empty() {
match ResponseFormat::try_from(format.as_str()) {
Ok(format) => {
return Ok(format);
}
Err(_) => {}
if let Ok(format) = ResponseFormat::try_from(format.as_str()) {
return Ok(format);
}
}
}

match ResponseFormat::try_from_headers(request_headers) {
Ok(format) => {
return Ok(format);
}
Err(_) => {
return Ok(ResponseFormat::Fs(String::new()));
}
Ok(format) => Ok(format),
Err(_) => Ok(ResponseFormat::Fs(String::new())),
}
}

Expand Down
14 changes: 6 additions & 8 deletions iroh-resolver/src/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl Path {
}

pub fn is_dir(&self) -> bool {
self.tail.len() > 0 && self.tail.last().unwrap().eq("")
!self.tail.is_empty() && self.tail.last().unwrap().is_empty()
}

pub fn push(&mut self, str: impl AsRef<str>) {
Expand All @@ -73,13 +73,13 @@ impl Path {
pub fn to_string_without_type(&self) -> String {
let mut s = format!("{}", self.root);
for part in &self.tail {
if part == "" {
if part.is_empty() {
continue;
}
s.push_str(&format!("/{}", part)[..]);
}
if self.is_dir() {
s.push_str("/");
s.push('/');
}
s
}
Expand All @@ -105,7 +105,7 @@ impl Display for Path {
write!(f, "/{}/{}", self.typ.as_str(), self.root)?;

for part in &self.tail {
if part == "" {
if part.is_empty() {
continue;
}
write!(f, "/{}", part)?;
Expand Down Expand Up @@ -1191,13 +1191,11 @@ mod tests {
let dir_test = "/ipfs/bafkreigh2akiscaildcqabsyg3dfr6chu3fgpregiymsck7e7aqa4s52zy/";
let non_dir_path: Path = non_dir_test.parse().unwrap();
let dir_path: Path = dir_test.parse().unwrap();
assert!(non_dir_path.tail().len() == 0);
assert!(non_dir_path.tail().is_empty());
assert!(dir_path.tail().len() == 1);
assert!(dir_path.tail()[0] == "");
assert!(dir_path.tail()[0].is_empty());

assert!(non_dir_path.to_string() == non_dir_test);
println!("dir_path: {}", dir_path.to_string());
println!("dir_test: {}", dir_test);
assert!(dir_path.to_string() == dir_test);
assert!(dir_path.is_dir());
assert!(!non_dir_path.is_dir());
Expand Down

0 comments on commit a3ab39b

Please sign in to comment.