mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 21:01:05 +00:00
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:
committed by
GitHub
parent
541692c4a8
commit
052be8bbef
@@ -1653,10 +1653,7 @@ impl<T: Config> Module<T> {
|
||||
// To decode the enum variant we only need the first byte.
|
||||
let mut buf = [0u8; 1];
|
||||
let key = <Preimages<T>>::hashed_key_for(proposal_hash);
|
||||
let bytes = match sp_io::storage::read(&key, &mut buf, 0) {
|
||||
Some(bytes) => bytes,
|
||||
None => return Err(Error::<T>::NotImminent.into()),
|
||||
};
|
||||
let bytes = sp_io::storage::read(&key, &mut buf, 0).ok_or_else(|| Error::<T>::NotImminent)?;
|
||||
// The value may be smaller that 1 byte.
|
||||
let mut input = &buf[0..buf.len().min(bytes as usize)];
|
||||
|
||||
@@ -1684,10 +1681,7 @@ impl<T: Config> Module<T> {
|
||||
// * at most 5 bytes to decode a `Compact<u32>`
|
||||
let mut buf = [0u8; 6];
|
||||
let key = <Preimages<T>>::hashed_key_for(proposal_hash);
|
||||
let bytes = match sp_io::storage::read(&key, &mut buf, 0) {
|
||||
Some(bytes) => bytes,
|
||||
None => return Err(Error::<T>::PreimageMissing.into()),
|
||||
};
|
||||
let bytes = sp_io::storage::read(&key, &mut buf, 0).ok_or_else(|| Error::<T>::PreimageMissing)?;
|
||||
// The value may be smaller that 6 bytes.
|
||||
let mut input = &buf[0..buf.len().min(bytes as usize)];
|
||||
|
||||
@@ -1761,10 +1755,7 @@ impl<T: Config> Module<T> {
|
||||
fn decode_compact_u32_at(key: &[u8]) -> Option<u32> {
|
||||
// `Compact<u32>` takes at most 5 bytes.
|
||||
let mut buf = [0u8; 5];
|
||||
let bytes = match sp_io::storage::read(&key, &mut buf, 0) {
|
||||
Some(bytes) => bytes,
|
||||
None => return None,
|
||||
};
|
||||
let bytes = sp_io::storage::read(&key, &mut buf, 0)?;
|
||||
// The value may be smaller than 5 bytes.
|
||||
let mut input = &buf[0..buf.len().min(bytes as usize)];
|
||||
match codec::Compact::<u32>::decode(&mut input) {
|
||||
|
||||
Reference in New Issue
Block a user