mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-09 18:47:59 +00:00
Simplify some Option / Result / ? operator patterns (#2920)
* Simplify some Option / Result / ? operator patterns When they identically match a combinator on those types. Tool-aided by [comby-rust](https://github.com/huitseeker/comby-rust). * adjust review comments Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
This commit is contained in:
committed by
GitHub
parent
c7ee98ab5f
commit
d4ddf8d7e8
@@ -188,10 +188,7 @@ impl<'a> Validators<'a> {
|
||||
finalized_blocks: &[(HeaderId, Option<S::Submitter>)],
|
||||
) -> Option<ChangeToEnact> {
|
||||
// if we haven't finalized any blocks, no changes may be finalized
|
||||
let newest_finalized_id = match finalized_blocks.last().map(|(id, _)| id) {
|
||||
Some(last_finalized_id) => last_finalized_id,
|
||||
None => return None,
|
||||
};
|
||||
let newest_finalized_id = finalized_blocks.last().map(|(id, _)| id)?;
|
||||
let oldest_finalized_id = finalized_blocks
|
||||
.first()
|
||||
.map(|(id, _)| id)
|
||||
|
||||
@@ -317,10 +317,7 @@ pub fn tranches_to_approve(
|
||||
tranches_with_gaps_filled
|
||||
.scan(Some(initial_state), |state, (tranche, assignments)| {
|
||||
// The `Option` here is used for early exit.
|
||||
let s = match state.take() {
|
||||
None => return None,
|
||||
Some(s) => s,
|
||||
};
|
||||
let s = state.take()?;
|
||||
|
||||
let clock_drift = s.clock_drift(no_show_duration);
|
||||
let drifted_tick_now = tick_now.saturating_sub(clock_drift);
|
||||
|
||||
@@ -463,8 +463,7 @@ impl State {
|
||||
if !range.is_empty() && !blocks.is_empty() {
|
||||
self.blocks_by_number
|
||||
.range(range)
|
||||
.map(|(_number, hashes)| hashes)
|
||||
.flatten()
|
||||
.flat_map(|(_number, hashes)| hashes)
|
||||
.for_each(|hash| {
|
||||
if let Some(entry) = blocks.get_mut(hash) {
|
||||
entry.known_by.remove(&peer_id);
|
||||
|
||||
@@ -101,8 +101,7 @@ fn check_fetch_retry() {
|
||||
let valid_candidate_hashes: HashSet<_> = state.cores
|
||||
.get(&state.relay_chain[1])
|
||||
.iter()
|
||||
.map(|v| v.iter())
|
||||
.flatten()
|
||||
.flat_map(|v| v.iter())
|
||||
.filter_map(|c| {
|
||||
match c {
|
||||
CoreState::Occupied(core) => Some(core.candidate_hash),
|
||||
|
||||
@@ -142,10 +142,7 @@ impl RequestFromBackersPhase {
|
||||
);
|
||||
loop {
|
||||
// Pop the next backer, and proceed to next phase if we're out.
|
||||
let validator_index = match self.shuffled_backers.pop() {
|
||||
None => return Err(RecoveryError::Unavailable),
|
||||
Some(i) => i,
|
||||
};
|
||||
let validator_index = self.shuffled_backers.pop().ok_or_else(|| RecoveryError::Unavailable)?;
|
||||
|
||||
// Request data.
|
||||
let (req, res) = OutgoingRequest::new(
|
||||
|
||||
@@ -1308,12 +1308,7 @@ async fn handle_incoming_message<'a>(
|
||||
ctx,
|
||||
req_sender,
|
||||
metrics,
|
||||
).await;
|
||||
|
||||
let statement = match statement {
|
||||
None => return None,
|
||||
Some(statement) => statement,
|
||||
};
|
||||
).await?;
|
||||
|
||||
match active_head.check_useful_or_unknown(statement.clone()) {
|
||||
Ok(()) => {},
|
||||
|
||||
Reference in New Issue
Block a user