Skip to content

Commit 6bed25c

Browse files
committed
fix clippy warnings
1 parent 91ea295 commit 6bed25c

File tree

9 files changed

+14
-41
lines changed

9 files changed

+14
-41
lines changed

adapter/src/ethereum.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl EthereumAdapter {
6262
let address = keystore_json["address"]
6363
.as_str()
6464
.map(eth_checksum::checksum)
65-
.ok_or_else(|| KeystoreError::AddressMissing)?;
65+
.ok_or(KeystoreError::AddressMissing)?;
6666

6767
let address = ValidatorId::try_from(&address).map_err(KeystoreError::AddressInvalid)?;
6868

@@ -256,10 +256,7 @@ impl Adapter for EthereumAdapter {
256256
}
257257

258258
fn get_auth(&self, validator: &ValidatorId) -> AdapterResult<String, Self::AdapterError> {
259-
let wallet = self
260-
.wallet
261-
.as_ref()
262-
.ok_or_else(|| AdapterError::LockedWallet)?;
259+
let wallet = self.wallet.as_ref().ok_or(AdapterError::LockedWallet)?;
263260

264261
let era = Utc::now().timestamp_millis() as f64 / 60000.0;
265262
let payload = Payload {

primitives/src/big_num.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -259,10 +259,7 @@ pub mod postgres {
259259
}
260260

261261
fn accepts(ty: &Type) -> bool {
262-
match *ty {
263-
Type::TEXT | Type::VARCHAR => true,
264-
_ => false,
265-
}
262+
matches!(*ty, Type::TEXT | Type::VARCHAR)
266263
}
267264
}
268265

@@ -276,10 +273,7 @@ pub mod postgres {
276273
}
277274

278275
fn accepts(ty: &Type) -> bool {
279-
match *ty {
280-
Type::TEXT | Type::VARCHAR => true,
281-
_ => false,
282-
}
276+
matches!(*ty, Type::TEXT | Type::VARCHAR)
283277
}
284278

285279
fn to_sql_checked(

primitives/src/merkle_tree.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ impl MerkleTree {
9999
pub fn new(data: &[MerkleItem]) -> Result<MerkleTree, Error> {
100100
let mut leaves: Vec<MerkleItem> = data.to_owned();
101101
// sort the MerkleTree leaves
102-
leaves.sort();
102+
leaves.sort_unstable();
103103
// remove duplicates **before** we check the leaves length
104104
leaves.dedup_by(|a, b| a == b);
105105

primitives/src/sentry.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,11 @@ pub enum Event {
7171

7272
impl Event {
7373
pub fn is_click_event(&self) -> bool {
74-
match *self {
75-
Event::Click { .. } => true,
76-
_ => false,
77-
}
74+
matches!(self, Event::Click { .. })
7875
}
7976

8077
pub fn is_impression_event(&self) -> bool {
81-
match *self {
82-
Event::Impression { .. } => true,
83-
_ => false,
84-
}
78+
matches!(self, Event::Impression { .. })
8579
}
8680
}
8781

primitives/src/validator.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,10 +231,7 @@ pub mod postgres {
231231
}
232232

233233
fn accepts(ty: &Type) -> bool {
234-
match *ty {
235-
Type::TEXT | Type::VARCHAR => true,
236-
_ => false,
237-
}
234+
matches!(*ty, Type::TEXT | Type::VARCHAR)
238235
}
239236
}
240237

sentry/src/access.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,7 @@ pub async fn check_access(
4444
channel: &Channel,
4545
events: &[Event],
4646
) -> Result<(), Error> {
47-
let is_close_event = |e: &Event| match e {
48-
Event::Close => true,
49-
_ => false,
50-
};
47+
let is_close_event = |e: &Event| matches!(e, Event::Close);
5148

5249
let has_close_event = events.iter().all(is_close_event);
5350
let current_time = Utc::now();

sentry/src/middleware/auth.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,12 @@ pub(crate) async fn for_request(
3636
let token = authorization
3737
.and_then(|hv| {
3838
hv.to_str()
39-
.map(|token_str| {
40-
if token_str.starts_with(prefix) {
41-
Some(token_str[prefix.len()..].to_string())
42-
} else {
43-
None
44-
}
45-
})
39+
.map(|token_str| token_str.strip_prefix(prefix))
4640
.transpose()
4741
})
4842
.transpose()?;
4943

50-
if let Some(ref token) = token {
44+
if let Some(token) = token {
5145
let adapter_session = match redis::cmd("GET")
5246
.arg(token)
5347
.query_async::<_, Option<String>>(&mut redis.clone())

sentry/src/middleware/channel.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub fn channel_load<'a, A: Adapter + 'static>(
2424
.map_err(|_| ResponseError::BadRequest("Wrong Channel Id".to_string()))?;
2525
let channel = get_channel_by_id(&app.pool, &channel_id)
2626
.await?
27-
.ok_or_else(|| ResponseError::NotFound)?;
27+
.ok_or(ResponseError::NotFound)?;
2828

2929
req.extensions_mut().insert(channel);
3030

@@ -58,7 +58,7 @@ pub fn channel_if_active<'a, A: Adapter + 'static>(
5858

5959
let channel = get_channel_by_id_and_validator(&app.pool, &channel_id, &validator_id)
6060
.await?
61-
.ok_or_else(|| ResponseError::NotFound)?;
61+
.ok_or(ResponseError::NotFound)?;
6262

6363
req.extensions_mut().insert(channel);
6464

sentry/src/routes/event_aggregate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub async fn list_channel_event_aggregates<A: Adapter>(
2424
let auth = req
2525
.extensions()
2626
.get::<Auth>()
27-
.ok_or_else(|| ResponseError::Unauthorized)?;
27+
.ok_or(ResponseError::Unauthorized)?;
2828

2929
let query =
3030
serde_urlencoded::from_str::<EventAggregatesQuery>(req.uri().query().unwrap_or(""))?;

0 commit comments

Comments
 (0)