Skip to content

Commit 2237906

Browse files
committed
clippy: use try_fold in place of fold in several places
1 parent 4f7782f commit 2237906

File tree

2 files changed

+13
-19
lines changed

2 files changed

+13
-19
lines changed

src/descriptor/key.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -852,8 +852,7 @@ fn parse_xkey_deriv<K: InnerXKey>(
852852
// step all the vectors of indexes contain a single element. If it did though, one of the
853853
// vectors contains more than one element.
854854
// Now transform this list of vectors of steps into distinct derivation paths.
855-
.fold(Ok(Vec::new()), |paths, index_list| {
856-
let mut paths = paths?;
855+
.try_fold(Vec::new(), |mut paths, index_list| {
857856
let mut index_list = index_list?.into_iter();
858857
let first_index = index_list
859858
.next()

src/miniscript/types/extra_props.rs

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -792,11 +792,11 @@ impl Property for ExtData {
792792
.iter()
793793
.rev()
794794
.enumerate()
795-
.fold(Some(0), |acc, (i, &(x, y))| {
795+
.try_fold(0, |acc, (i, &(x, y))| {
796796
if i <= k {
797-
opt_add(acc, x)
797+
x.map(|x| acc + x)
798798
} else {
799-
opt_add(acc, y)
799+
y.map(|y| acc + y)
800800
}
801801
});
802802

@@ -805,11 +805,11 @@ impl Property for ExtData {
805805
.iter()
806806
.rev()
807807
.enumerate()
808-
.fold(Some(0), |acc, (i, &(x, y))| {
808+
.try_fold(0, |acc, (i, &(x, y))| {
809809
if i <= k {
810-
opt_max(acc, x)
810+
x.map(|x| acc + x)
811811
} else {
812-
opt_max(acc, y)
812+
y.map(|y| acc + y)
813813
}
814814
});
815815

@@ -819,11 +819,11 @@ impl Property for ExtData {
819819
max_sat_size_vec
820820
.iter()
821821
.enumerate()
822-
.fold(Some((0, 0)), |acc, (i, &(x, y))| {
822+
.try_fold((0, 0), |acc, (i, &(x, y))| {
823823
if i <= k {
824-
opt_tuple_add(acc, x)
824+
x.map(|(x0, x1)| (acc.0 + x0, acc.1 + x1))
825825
} else {
826-
opt_tuple_add(acc, y)
826+
y.map(|(y0, y1)| (acc.0 + y0, acc.1 + y1))
827827
}
828828
});
829829

@@ -832,11 +832,11 @@ impl Property for ExtData {
832832
ops_count_sat_vec
833833
.iter()
834834
.enumerate()
835-
.fold(Some(0), |acc, (i, &(x, y))| {
835+
.try_fold(0, |acc, (i, &(x, y))| {
836836
if i <= k {
837-
opt_add(acc, x)
837+
x.map(|x| acc + x)
838838
} else {
839-
opt_add(acc, Some(y))
839+
Some(acc + y)
840840
}
841841
});
842842

@@ -1049,11 +1049,6 @@ fn opt_max<T: Ord>(a: Option<T>, b: Option<T>) -> Option<T> {
10491049
/// Returns Some(x+y) is both x and y are Some. Otherwise, returns `None`.
10501050
fn opt_add(a: Option<usize>, b: Option<usize>) -> Option<usize> { a.and_then(|x| b.map(|y| x + y)) }
10511051

1052-
/// Returns Some((x0+y0, x1+y1)) is both x and y are Some. Otherwise, returns `None`.
1053-
fn opt_tuple_add(a: Option<(usize, usize)>, b: Option<(usize, usize)>) -> Option<(usize, usize)> {
1054-
a.and_then(|x| b.map(|(w, s)| (w + x.0, s + x.1)))
1055-
}
1056-
10571052
#[cfg(test)]
10581053
mod tests {
10591054
use super::*;

0 commit comments

Comments
 (0)