mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-21 15:35:42 +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>)],
|
finalized_blocks: &[(HeaderId, Option<S::Submitter>)],
|
||||||
) -> Option<ChangeToEnact> {
|
) -> Option<ChangeToEnact> {
|
||||||
// if we haven't finalized any blocks, no changes may be finalized
|
// if we haven't finalized any blocks, no changes may be finalized
|
||||||
let newest_finalized_id = match finalized_blocks.last().map(|(id, _)| id) {
|
let newest_finalized_id = finalized_blocks.last().map(|(id, _)| id)?;
|
||||||
Some(last_finalized_id) => last_finalized_id,
|
|
||||||
None => return None,
|
|
||||||
};
|
|
||||||
let oldest_finalized_id = finalized_blocks
|
let oldest_finalized_id = finalized_blocks
|
||||||
.first()
|
.first()
|
||||||
.map(|(id, _)| id)
|
.map(|(id, _)| id)
|
||||||
|
|||||||
@@ -317,10 +317,7 @@ pub fn tranches_to_approve(
|
|||||||
tranches_with_gaps_filled
|
tranches_with_gaps_filled
|
||||||
.scan(Some(initial_state), |state, (tranche, assignments)| {
|
.scan(Some(initial_state), |state, (tranche, assignments)| {
|
||||||
// The `Option` here is used for early exit.
|
// The `Option` here is used for early exit.
|
||||||
let s = match state.take() {
|
let s = state.take()?;
|
||||||
None => return None,
|
|
||||||
Some(s) => s,
|
|
||||||
};
|
|
||||||
|
|
||||||
let clock_drift = s.clock_drift(no_show_duration);
|
let clock_drift = s.clock_drift(no_show_duration);
|
||||||
let drifted_tick_now = tick_now.saturating_sub(clock_drift);
|
let drifted_tick_now = tick_now.saturating_sub(clock_drift);
|
||||||
|
|||||||
@@ -463,8 +463,7 @@ impl State {
|
|||||||
if !range.is_empty() && !blocks.is_empty() {
|
if !range.is_empty() && !blocks.is_empty() {
|
||||||
self.blocks_by_number
|
self.blocks_by_number
|
||||||
.range(range)
|
.range(range)
|
||||||
.map(|(_number, hashes)| hashes)
|
.flat_map(|(_number, hashes)| hashes)
|
||||||
.flatten()
|
|
||||||
.for_each(|hash| {
|
.for_each(|hash| {
|
||||||
if let Some(entry) = blocks.get_mut(hash) {
|
if let Some(entry) = blocks.get_mut(hash) {
|
||||||
entry.known_by.remove(&peer_id);
|
entry.known_by.remove(&peer_id);
|
||||||
|
|||||||
@@ -101,8 +101,7 @@ fn check_fetch_retry() {
|
|||||||
let valid_candidate_hashes: HashSet<_> = state.cores
|
let valid_candidate_hashes: HashSet<_> = state.cores
|
||||||
.get(&state.relay_chain[1])
|
.get(&state.relay_chain[1])
|
||||||
.iter()
|
.iter()
|
||||||
.map(|v| v.iter())
|
.flat_map(|v| v.iter())
|
||||||
.flatten()
|
|
||||||
.filter_map(|c| {
|
.filter_map(|c| {
|
||||||
match c {
|
match c {
|
||||||
CoreState::Occupied(core) => Some(core.candidate_hash),
|
CoreState::Occupied(core) => Some(core.candidate_hash),
|
||||||
|
|||||||
@@ -142,10 +142,7 @@ impl RequestFromBackersPhase {
|
|||||||
);
|
);
|
||||||
loop {
|
loop {
|
||||||
// Pop the next backer, and proceed to next phase if we're out.
|
// Pop the next backer, and proceed to next phase if we're out.
|
||||||
let validator_index = match self.shuffled_backers.pop() {
|
let validator_index = self.shuffled_backers.pop().ok_or_else(|| RecoveryError::Unavailable)?;
|
||||||
None => return Err(RecoveryError::Unavailable),
|
|
||||||
Some(i) => i,
|
|
||||||
};
|
|
||||||
|
|
||||||
// Request data.
|
// Request data.
|
||||||
let (req, res) = OutgoingRequest::new(
|
let (req, res) = OutgoingRequest::new(
|
||||||
|
|||||||
@@ -1308,12 +1308,7 @@ async fn handle_incoming_message<'a>(
|
|||||||
ctx,
|
ctx,
|
||||||
req_sender,
|
req_sender,
|
||||||
metrics,
|
metrics,
|
||||||
).await;
|
).await?;
|
||||||
|
|
||||||
let statement = match statement {
|
|
||||||
None => return None,
|
|
||||||
Some(statement) => statement,
|
|
||||||
};
|
|
||||||
|
|
||||||
match active_head.check_useful_or_unknown(statement.clone()) {
|
match active_head.check_useful_or_unknown(statement.clone()) {
|
||||||
Ok(()) => {},
|
Ok(()) => {},
|
||||||
|
|||||||
Reference in New Issue
Block a user