From 56bac34f1bde00948c4eff5e232b57ae196c26c1 Mon Sep 17 00:00:00 2001 From: benthecarman Date: Sat, 11 Jun 2022 21:48:03 -0500 Subject: [PATCH] Match on Option instead of using is_none --- senseicore/src/channels.rs | 9 ++++----- src/grpc/admin.rs | 18 ++++++++---------- src/grpc/utils.rs | 16 +++++++--------- 3 files changed, 19 insertions(+), 24 deletions(-) diff --git a/senseicore/src/channels.rs b/senseicore/src/channels.rs index 9268ce3..0c69886 100644 --- a/senseicore/src/channels.rs +++ b/senseicore/src/channels.rs @@ -131,7 +131,7 @@ impl ChannelOpener { .map(|(request, result)| { if result.is_ok() { let mut channel_counterparty_node_id = None; - let event = events.iter().find(|event| { + let event_opt = events.iter().find(|event| { if let SenseiEvent::FundingGenerationReady { user_channel_id, counterparty_node_id, @@ -146,10 +146,9 @@ impl ChannelOpener { false }); - if event.is_none() { - (request, Err(Error::FundingGenerationNeverHappened), None) - } else { - (request, result, channel_counterparty_node_id) + match event_opt { + None => (request, Err(Error::FundingGenerationNeverHappened), None), + Some(_) => (request, result, channel_counterparty_node_id), } } else { (request, result, None) diff --git a/src/grpc/admin.rs b/src/grpc/admin.rs index 614551c..5beb41e 100644 --- a/src/grpc/admin.rs +++ b/src/grpc/admin.rs @@ -385,17 +385,15 @@ impl AdminService { } fn raw_token_from_metadata(&self, metadata: MetadataMap) -> Result { - let token = metadata.get("token"); - - if token.is_none() { - return Err(Status::unauthenticated("token is required")); + let token_opt = metadata.get("token"); + + match token_opt { + Some(token) => token + .to_str() + .map(String::from) + .map_err(|_e| Status::unauthenticated("invalid token: must be ascii")), + None => Err(Status::unauthenticated("token is required")), } - - token - .unwrap() - .to_str() - .map(String::from) - .map_err(|_e| Status::unauthenticated("invalid token: must be ascii")) } } diff --git a/src/grpc/utils.rs b/src/grpc/utils.rs index 19ab727..3b504d5 100644 --- a/src/grpc/utils.rs +++ b/src/grpc/utils.rs @@ -1,15 +1,13 @@ use tonic::{metadata::MetadataMap, Status}; pub fn raw_macaroon_from_metadata(metadata: MetadataMap) -> Result { - let macaroon = metadata.get("macaroon"); + let macaroon_opt = metadata.get("macaroon"); - if macaroon.is_none() { - return Err(Status::unauthenticated("macaroon is required")); + match macaroon_opt { + Some(macaroon) => macaroon + .to_str() + .map(String::from) + .map_err(|_e| Status::unauthenticated("invalid macaroon: must be ascii")), + None => Err(Status::unauthenticated("macaroon is required")), } - - macaroon - .unwrap() - .to_str() - .map(String::from) - .map_err(|_e| Status::unauthenticated("invalid macaroon: must be ascii")) }