Simplify some Option / Result / ? operator patterns (#8653)

* Simplify some Option / Result / ? operator patterns

When those match a combinator exactly.

Tool-aided by [comby-rust](https://github.com/huitseeker/comby-rust).

* adjust after review

* adjust post-review
This commit is contained in:
François Garillot
2021-04-23 09:36:10 -04:00
committed by GitHub
parent 541692c4a8
commit 052be8bbef
37 changed files with 77 additions and 188 deletions
+4 -8
View File
@@ -226,10 +226,8 @@ impl<Block: BlockT> Blockchain<Block> {
/// Set an existing block as head.
pub fn set_head(&self, id: BlockId<Block>) -> sp_blockchain::Result<()> {
let header = match self.header(id)? {
Some(h) => h,
None => return Err(sp_blockchain::Error::UnknownBlock(format!("{}", id))),
};
let header = self.header(id)?
.ok_or_else(|| sp_blockchain::Error::UnknownBlock(format!("{}", id)))?;
self.apply_head(&header)
}
@@ -760,10 +758,8 @@ impl<Block: BlockT> backend::Backend<Block> for Backend<Block> where Block::Hash
_ => {},
}
match self.blockchain.id(block).and_then(|id| self.states.read().get(&id).cloned()) {
Some(state) => Ok(state),
None => Err(sp_blockchain::Error::UnknownBlock(format!("{}", block))),
}
self.blockchain.id(block).and_then(|id| self.states.read().get(&id).cloned())
.ok_or_else(|| sp_blockchain::Error::UnknownBlock(format!("{}", block)))
}
fn revert(