Skip to content

Commit

Permalink
Ran fmt and clippy (#169)
Browse files Browse the repository at this point in the history
Added lint github workflow

Added extra clippy fixes
  • Loading branch information
jspspike authored Dec 2, 2021
1 parent 1e70061 commit b4cd8a6
Show file tree
Hide file tree
Showing 17 changed files with 48 additions and 33 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Linters

on: [pull_request]

jobs:
rustfmt:
name: Formatter
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Check Formatting
run: cargo fmt --all -- --check

- name: Check for idiomatic code
run: cargo clippy --all --all-features -- -D warnings
8 changes: 4 additions & 4 deletions cloudflare-e2e-test/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ async fn tests<ApiClientType: ApiClient>(
api_client: &ApiClientType,
account_id: &str,
) -> anyhow::Result<()> {
test_lb_pool(api_client, &account_id).await?;
test_lb_pool(api_client, account_id).await?;
println!("Tests passed");
Ok(())
}
Expand Down Expand Up @@ -137,18 +137,18 @@ async fn main() -> anyhow::Result<()> {
Environment::Production,
)?;

tests(&api_client, &account_id).await
tests(&api_client, account_id).await
}

pub trait ResultExt<T, E: Display> {
/// Convenience function for logging errors inside results.
/// Basically just `map_err` except the closure argument doesn't return anything,
/// and `.log_err` always returns `self`.
fn log_err<L: FnOnce(&E) -> ()>(self, log: L) -> Self;
fn log_err<L: FnOnce(&E)>(self, log: L) -> Self;
}

impl<T, E: Display> ResultExt<T, E> for Result<T, E> {
fn log_err<L: FnOnce(&E) -> ()>(self, log: L) -> Self {
fn log_err<L: FnOnce(&E)>(self, log: L) -> Self {
if let Err(e) = &self {
log(e)
}
Expand Down
2 changes: 1 addition & 1 deletion cloudflare-examples/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {

for (section_name, section) in matched_sections {
(section.function)(
&matches.subcommand_matches(section_name).unwrap(),
matches.subcommand_matches(section_name).unwrap(),
&api_client,
);
}
Expand Down
2 changes: 1 addition & 1 deletion cloudflare/src/endpoints/account/list_accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ impl Endpoint<Vec<Account>, ListAccountsParams> for ListAccounts {
Method::Get
}
fn path(&self) -> String {
format!("accounts")
"accounts".to_string()
}
fn query(&self) -> Option<ListAccountsParams> {
self.params.clone()
Expand Down
5 changes: 4 additions & 1 deletion cloudflare/src/endpoints/argo_tunnel/delete_tunnel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ impl<'a> Endpoint<Tunnel> for DeleteTunnel<'a> {
Method::Delete
}
fn path(&self) -> String {
format!("accounts/{}/tunnels/{}", self.account_identifier, self.tunnel_id)
format!(
"accounts/{}/tunnels/{}",
self.account_identifier, self.tunnel_id
)
}
}
1 change: 1 addition & 0 deletions cloudflare/src/endpoints/dns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ pub struct Meta {
/// here as an associated, strongly typed value.
#[derive(Deserialize, Serialize, Clone, Debug)]
#[serde(tag = "type")]
#[allow(clippy::upper_case_acronyms)]
pub enum DnsContent {
A { content: Ipv4Addr },
AAAA { content: Ipv6Addr },
Expand Down
5 changes: 4 additions & 1 deletion cloudflare/src/endpoints/load_balancing/create_lb.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use crate::endpoints::load_balancing::{LbPoolId, SteeringPolicy, SessionAffinityAttributes, LbPoolMapping, SessionAffinity, LoadBalancer};
use crate::endpoints::load_balancing::{
LbPoolId, LbPoolMapping, LoadBalancer, SessionAffinity, SessionAffinityAttributes,
SteeringPolicy,
};
use crate::framework::endpoint::{Endpoint, Method};

/// Create Load Balancer
Expand Down
7 changes: 3 additions & 4 deletions cloudflare/src/endpoints/load_balancing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub mod pool_details;
use crate::framework::response::ApiResult;
use chrono::offset::Utc;
use chrono::DateTime;
use std::collections::{HashSet, HashMap};
use std::collections::{HashMap, HashSet};
use std::hash::{Hash, Hasher};
use std::net::IpAddr;

Expand Down Expand Up @@ -80,7 +80,7 @@ pub enum SessionAffinity {
Nil,
None,
Cookie,
IpCookie
IpCookie,
}

#[derive(Eq, PartialEq, Deserialize, Serialize, Clone, Debug)]
Expand All @@ -104,12 +104,11 @@ pub enum Secure {
/// `Auto` maps to `Always` if Always Use HTTPS is set, or `Never` otherwise.
Auto,
Always,
Never
Never,
}

impl ApiResult for LoadBalancer {}


/// A pool is a set of origins that requests could be routed to (e.g. each of your data centers or
/// regions have its own pool).
/// Requests will be routed to particular pools according to your steering policy, and then balanced
Expand Down
1 change: 0 additions & 1 deletion cloudflare/src/endpoints/workers/delete_do.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,3 @@ impl<'a> Endpoint<(), (), ()> for DeleteDurableObject<'a> {
)
}
}

2 changes: 1 addition & 1 deletion cloudflare/src/endpoints/workers/delete_script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::framework::endpoint::{Endpoint, Method};
use crate::framework::response::ApiResult;

/// Delete Workers script
/// https://api.cloudflare.com/#worker-script-delete-worker
/// https://api.cloudflare.com/#worker-script-delete-worker
#[derive(Debug)]
pub struct DeleteScript<'a> {
/// account id of owner of the script
Expand Down
5 changes: 2 additions & 3 deletions cloudflare/src/endpoints/workers/list_bindings.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::WorkersBinding;
use crate::framework::endpoint::{Endpoint, Method};
use super::WorkersBinding;

/// List Bindings
/// Lists all bindings for a given script
Expand All @@ -19,8 +19,7 @@ impl<'a> Endpoint<Vec<WorkersBinding>> for ListBindings<'a> {
fn path(&self) -> String {
format!(
"accounts/{}/workers/scripts/{}/bindings",
self.account_id,
self.script_name
self.account_id, self.script_name
)
}
}
3 changes: 1 addition & 2 deletions cloudflare/src/endpoints/workers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,4 @@ pub struct WorkersBinding {
}

impl ApiResult for WorkersBinding {}
impl ApiResult for Vec<WorkersBinding>{}

impl ApiResult for Vec<WorkersBinding> {}
4 changes: 2 additions & 2 deletions cloudflare/src/endpoints/workerskv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ pub struct Key {
pub fn deserialize_option_timestamp<'de, D>(
deserializer: D,
) -> Result<Option<DateTime<Utc>>, D::Error>
where
D: Deserializer<'de>,
where
D: Deserializer<'de>,
{
let s: Option<i64> = Option::deserialize(deserializer)?;
if let Some(s) = s {
Expand Down
14 changes: 6 additions & 8 deletions cloudflare/src/framework/async_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ use crate::framework::{
Environment, HttpApiClientConfig,
};
use async_trait::async_trait;
use reqwest;
use serde::Serialize;
use cfg_if::cfg_if;
use serde::Serialize;

#[async_trait]
pub trait ApiClient {
Expand Down Expand Up @@ -47,8 +46,7 @@ impl Client {
environment: Environment,
) -> anyhow::Result<Client> {
#[allow(unused_mut)]
let mut builder = reqwest::Client::builder()
.default_headers(config.default_headers);
let mut builder = reqwest::Client::builder().default_headers(config.default_headers);

cfg_if! {
// There are no timeouts in wasm. The property is documented as no-op in wasm32.
Expand Down Expand Up @@ -104,10 +102,10 @@ impl ApiClient for Client {
&self,
endpoint: &(dyn Endpoint<ResultType, QueryType, BodyType> + Send + Sync),
) -> ApiResponse<ResultType>
where
ResultType: ApiResult,
QueryType: Serialize,
BodyType: Serialize,
where
ResultType: ApiResult,
QueryType: Serialize,
BodyType: Serialize,
{
self.request_handle(endpoint).await
}
Expand Down
1 change: 0 additions & 1 deletion cloudflare/src/framework/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use crate::framework::async_api;
use crate::framework::endpoint::{Endpoint, Method};
use crate::framework::response::{ApiError, ApiErrors, ApiFailure, ApiResponse, ApiResult};
use async_trait::async_trait;
use reqwest;
use std::collections::HashMap;

pub struct MockApiClient {}
Expand Down
4 changes: 2 additions & 2 deletions cloudflare/src/framework/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ This module controls how requests are sent to Cloudflare's API, and how response
pub mod apiclient;
pub mod async_api;
pub mod auth;
#[cfg(not(target_arch = "wasm32"))] // There is no blocking implementation for wasm.
#[cfg(not(target_arch = "wasm32"))] // There is no blocking implementation for wasm.
pub mod blocking_api;
pub mod endpoint;
pub mod json_utils;
#[cfg(not(target_arch = "wasm32"))] // The mock contains a blocking implementation.
#[cfg(not(target_arch = "wasm32"))] // The mock contains a blocking implementation.
pub mod mock;
mod reqwest_adaptors;
pub mod response;
Expand Down
1 change: 0 additions & 1 deletion cloudflare/src/framework/reqwest_adaptors.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::framework::endpoint::Method;
use reqwest;

pub fn match_reqwest_method(method: Method) -> reqwest::Method {
match method {
Expand Down

0 comments on commit b4cd8a6

Please sign in to comment.