Skip to content

Commit a7c9338

Browse files
authored
Merge pull request #489 from AmbireTech/rust-1.60
Run rustfmt & clippy because of Rust 1.60
2 parents fe5fdc6 + 4f1019c commit a7c9338

File tree

12 files changed

+44
-56
lines changed

12 files changed

+44
-56
lines changed

adview-manager/src/lib.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ fn get_unit_html(
162162
) -> String {
163163
// replace all `"` quotes with a single quote `'`
164164
// these values are used inside `onclick` & `onload` html attributes
165-
let on_load = on_load.replace("\"", "'");
166-
let on_click = on_click.replace("\"", "'");
165+
let on_load = on_load.replace('\"', "'");
166+
let on_click = on_click.replace('\"', "'");
167167
let image_url = normalize_url(&ad_unit.media_url);
168168

169169
let element_html = if is_video(ad_unit) {
@@ -460,7 +460,7 @@ impl Manager {
460460
// Apply targeting, now with adView.* variables, and sort the resulting ad units
461461
let mut units_with_price = m_campaigns
462462
.iter()
463-
.map(|m_campaign| {
463+
.flat_map(|m_campaign| {
464464
// since we are in a Iterator.map(), we can't use async, so we block
465465
if block_on(self.is_campaign_sticky(m_campaign.campaign.id)) {
466466
return vec![];
@@ -498,7 +498,6 @@ impl Manager {
498498
.map(|uwp| (uwp.clone(), campaign_id))
499499
.collect()
500500
})
501-
.flatten()
502501
.filter(|x| !(self.options.disabled_video && is_video(&x.0.unit)))
503502
.collect::<Vec<_>>();
504503

primitives/src/balances.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,11 @@ impl<S: BalancesState> Balances<S> {
7373
self.spenders
7474
.values()
7575
.sum::<Option<UnifiedNum>>()
76-
.map(|spenders| {
76+
.and_then(|spenders| {
7777
let earners = self.earners.values().sum::<Option<UnifiedNum>>()?;
7878

7979
Some((earners, spenders))
8080
})
81-
.flatten()
8281
}
8382
}
8483

sentry/src/access.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,7 @@ fn forbidden_referrer(session: &Session) -> bool {
143143
match session
144144
.referrer_header
145145
.as_ref()
146-
.map(|rf| rf.split('/').nth(2))
147-
.flatten()
146+
.and_then(|rf| rf.split('/').nth(2))
148147
{
149148
Some(hostname) => {
150149
hostname == "localhost"

sentry/src/db.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,15 +173,15 @@ pub mod tests_postgres {
173173
};
174174
let manager = Manager::new(POSTGRES_CONFIG.clone(), manager_config, db_prefix)?;
175175

176-
Ok(Pool::builder(manager)
176+
Pool::builder(manager)
177177
.max_size(15)
178178
.build()
179179
.map_err(|err| match err {
180180
deadpool::managed::BuildError::Backend(err) => err,
181181
deadpool::managed::BuildError::NoRuntimeSpecified(message) => {
182182
Error::Build(deadpool::managed::BuildError::NoRuntimeSpecified(message))
183183
}
184-
})?)
184+
})
185185
}
186186

187187
/// A Database is used to isolate test runs from each other

sentry/src/middleware/auth.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,7 @@ async fn for_request<C: Locked>(
8282
let referrer = req
8383
.headers()
8484
.get(REFERER)
85-
.map(|hv| hv.to_str().ok().map(ToString::to_string))
86-
.flatten();
85+
.and_then(|hv| hv.to_str().ok().map(ToString::to_string));
8786

8887
let session = Session {
8988
ip: get_request_ip(&req),
@@ -147,8 +146,7 @@ fn get_request_ip(req: &Request<Body>) -> Option<String> {
147146
.get("true-client-ip")
148147
.or_else(|| req.headers().get("x-forwarded-for"))
149148
.and_then(|hv| hv.to_str().map(ToString::to_string).ok())
150-
.map(|token| token.split(',').next().map(ToString::to_string))
151-
.flatten()
149+
.and_then(|token| token.split(',').next().map(ToString::to_string))
152150
}
153151

154152
#[cfg(test)]

sentry/src/middleware/campaign.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ impl<C: Locked + 'static> Middleware<C> for CampaignLoad {
3434
let campaign_context = application
3535
.config
3636
.find_chain_of(campaign.channel.token)
37-
.ok_or(ResponseError::BadRequest(
38-
"Channel token not whitelisted".to_string(),
39-
))?
37+
.ok_or_else(|| ResponseError::BadRequest("Channel token not whitelisted".to_string()))?
4038
.with_campaign(campaign);
4139

4240
// If this is an authenticated call

sentry/src/middleware/channel.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ fn channel_load<C: Locked>(
4343
.await?
4444
.ok_or(ResponseError::NotFound)?;
4545

46-
let channel_context = app.config.find_chain_of(channel.token).ok_or(ResponseError::FailedValidation("Channel token is not whitelisted in this validator".into()))?.with_channel(channel);
46+
let channel_context = app.config.find_chain_of(channel.token).ok_or_else(|| ResponseError::FailedValidation("Channel token is not whitelisted in this validator".into()))?.with_channel(channel);
4747

4848
// If this is an authenticated call
4949
// Check if the Channel context (Chain Id) aligns with the Authentication token Chain id

sentry/src/payout.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub fn get_payout(
5050
ad_slot_type: ad_unit.map(|u| u.ad_type.clone()).unwrap_or_default(),
5151
publisher_id: *publisher,
5252
country: session.country.clone(),
53-
event_type: event_type,
53+
event_type,
5454
seconds_since_epoch: Utc::now(),
5555
user_agent_os: session.os.clone(),
5656
user_agent_browser_family: None,

sentry/src/routes/campaign.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ pub async fn update_latest_spendable<C>(
7474
where
7575
C: Locked + 'static,
7676
{
77-
let latest_deposit = adapter.get_deposit(&channel_context, address).await?;
77+
let latest_deposit = adapter.get_deposit(channel_context, address).await?;
7878

7979
let spendable = Spendable {
8080
spender: address,
@@ -255,7 +255,7 @@ where
255255

256256
// Channel insertion can never create a `SqlState::UNIQUE_VIOLATION`
257257
// Insert the Campaign too
258-
match insert_campaign(&app.pool, &campaign).await {
258+
match insert_campaign(&app.pool, campaign).await {
259259
Err(error) => {
260260
error!(&app.logger, "{}", &error; "module" => "create_campaign");
261261
match error {
@@ -398,7 +398,7 @@ pub mod update_campaign {
398398
// *NOTE*: To close a campaign set campaignBudget to campaignSpent so that spendable == 0
399399

400400
let delta_budget = if let Some(new_budget) = modify_campaign.budget {
401-
get_delta_budget(campaign_remaining, &campaign, new_budget).await?
401+
get_delta_budget(campaign_remaining, campaign, new_budget).await?
402402
} else {
403403
None
404404
};

sentry/src/routes/channel.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ pub async fn add_spender_leaf<C: Locked + 'static>(
324324
let latest_spendable = match latest_spendable {
325325
Some(spendable) => spendable,
326326
None => {
327-
create_or_update_spendable_document(&app.adapter, app.pool.clone(), &channel, spender)
327+
create_or_update_spendable_document(&app.adapter, app.pool.clone(), channel, spender)
328328
.await?
329329
}
330330
};
@@ -451,7 +451,7 @@ pub async fn channel_payout<C: Locked + 'static>(
451451
.map_err(|e| ResponseError::FailedValidation(e.to_string()))?;
452452

453453
// Handling the case where a request with an empty body comes through
454-
if to_pay.payouts.len() == 0 {
454+
if to_pay.payouts.is_empty() {
455455
return Err(ResponseError::FailedValidation(
456456
"Request has empty payouts".to_string(),
457457
));
@@ -504,9 +504,11 @@ pub async fn channel_payout<C: Locked + 'static>(
504504
fetch_spendable(app.pool.clone(), &spender, &channel_context.context.id())
505505
.await
506506
.map_err(|err| ResponseError::BadRequest(err.to_string()))?
507-
.ok_or(ResponseError::BadRequest(
508-
"There is no spendable amount for the spender in this Channel".to_string(),
509-
))?;
507+
.ok_or_else(|| {
508+
ResponseError::BadRequest(
509+
"There is no spendable amount for the spender in this Channel".to_string(),
510+
)
511+
})?;
510512
let total_deposited = latest_spendable.deposit.total;
511513

512514
let available_for_payout = total_deposited

0 commit comments

Comments
 (0)