Skip to content

Commit

Permalink
cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
talhahwahla committed Jan 8, 2024
1 parent 49a8826 commit 6cb5d4e
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions src/ipinfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,17 @@ impl IpInfo {
ips: &[&str],
batch_config: BatchReqOpts,
) -> Result<HashMap<String, IpDetails>, IpError> {
self.lookup_batch_internal(ips, batch_config, BASE_URL).await
self.lookup_batch_internal(ips, batch_config, BASE_URL)
.await
}

pub async fn lookup_batch_v6(
&mut self,
ips: &[&str],
batch_config: BatchReqOpts,
) -> Result<HashMap<String, IpDetails>, IpError> {
self.lookup_batch_internal(ips, batch_config, BASE_URL_V6).await
self.lookup_batch_internal(ips, batch_config, BASE_URL_V6)
.await
}

async fn lookup_batch_internal(
Expand All @@ -201,8 +203,11 @@ impl IpInfo {
) -> Result<HashMap<String, IpDetails>, IpError> {
// Handle the total timeout condition
if let Some(total_timeout) = batch_config.timeout_total {
match timeout(total_timeout, self._lookup_batch(ips, batch_config, base_url))
.await
match timeout(
total_timeout,
self._lookup_batch(ips, batch_config, base_url),
)
.await
{
Ok(result) => result,
Err(_) => Err(err!(TimeOutError)),
Expand All @@ -217,7 +222,7 @@ impl IpInfo {
&mut self,
ips: &[&str],
batch_config: BatchReqOpts,
base_url: &str
base_url: &str,
) -> Result<HashMap<String, IpDetails>, IpError> {
let mut results: HashMap<String, IpDetails> = HashMap::new();

Expand Down Expand Up @@ -251,7 +256,8 @@ impl IpInfo {

// Make batched requests
for batch in work.chunks(batch_config.batch_size as usize) {
let response = self.batch_request(client.clone(), batch, base_url).await?;
let response =
self.batch_request(client.clone(), batch, base_url).await?;
results.extend(response);
}

Expand All @@ -275,7 +281,7 @@ impl IpInfo {
&self,
client: reqwest::Client,
ips: &[&str],
base_url: &str
base_url: &str,
) -> Result<HashMap<String, IpDetails>, IpError> {
// Lookup cache misses which are not bogon
let response = client
Expand Down Expand Up @@ -329,7 +335,11 @@ impl IpInfo {
self.lookup_internal(ip, BASE_URL_V6).await
}

async fn lookup_internal(&mut self, ip: &str, base_url: &str) -> Result<IpDetails, IpError> {
async fn lookup_internal(
&mut self,
ip: &str,
base_url: &str,
) -> Result<IpDetails, IpError> {
if is_bogon(ip) {
return Ok(IpDetails {
ip: ip.to_string(),
Expand Down Expand Up @@ -400,7 +410,11 @@ impl IpInfo {
self.get_map_internal(ips, BASE_URL_V6).await
}

async fn get_map_internal(&self, ips: &[&str], base_url: &str) -> Result<String, IpError> {
async fn get_map_internal(
&self,
ips: &[&str],
base_url: &str,
) -> Result<String, IpError> {
if ips.len() > 500_000 {
return Err(err!(MapLimitError));
}
Expand Down

0 comments on commit 6cb5d4e

Please sign in to comment.