##// END OF EJS Templates
rust: move `filter_map_results` to public util...
Raphaël Gomès -
r50874:f5b16897 default
parent child Browse files
Show More
@@ -15,6 +15,7 b' use crate::dirstate::ParentFileData;'
15 use crate::dirstate::StateMapIter;
15 use crate::dirstate::StateMapIter;
16 use crate::dirstate::TruncatedTimestamp;
16 use crate::dirstate::TruncatedTimestamp;
17 use crate::matchers::Matcher;
17 use crate::matchers::Matcher;
18 use crate::utils::filter_map_results;
18 use crate::utils::hg_path::{HgPath, HgPathBuf};
19 use crate::utils::hg_path::{HgPath, HgPathBuf};
19 use crate::DirstateEntry;
20 use crate::DirstateEntry;
20 use crate::DirstateError;
21 use crate::DirstateError;
@@ -912,26 +913,6 b" impl<'on_disk> DirstateMap<'on_disk> {"
912 }
913 }
913 }
914 }
914
915
915 /// Like `Iterator::filter_map`, but over a fallible iterator of `Result`s.
916 ///
917 /// The callback is only called for incoming `Ok` values. Errors are passed
918 /// through as-is. In order to let it use the `?` operator the callback is
919 /// expected to return a `Result` of `Option`, instead of an `Option` of
920 /// `Result`.
921 fn filter_map_results<'a, I, F, A, B, E>(
922 iter: I,
923 f: F,
924 ) -> impl Iterator<Item = Result<B, E>> + 'a
925 where
926 I: Iterator<Item = Result<A, E>> + 'a,
927 F: Fn(A) -> Result<Option<B>, E> + 'a,
928 {
929 iter.filter_map(move |result| match result {
930 Ok(node) => f(node).transpose(),
931 Err(e) => Some(Err(e)),
932 })
933 }
934
935 type DebugDirstateTuple<'a> = (&'a HgPath, (u8, i32, i32, i32));
916 type DebugDirstateTuple<'a> = (&'a HgPath, (u8, i32, i32, i32));
936
917
937 impl OwningDirstateMap {
918 impl OwningDirstateMap {
@@ -477,3 +477,23 b' where'
477 Ok(())
477 Ok(())
478 }
478 }
479 }
479 }
480
481 /// Like `Iterator::filter_map`, but over a fallible iterator of `Result`s.
482 ///
483 /// The callback is only called for incoming `Ok` values. Errors are passed
484 /// through as-is. In order to let it use the `?` operator the callback is
485 /// expected to return a `Result` of `Option`, instead of an `Option` of
486 /// `Result`.
487 pub fn filter_map_results<'a, I, F, A, B, E>(
488 iter: I,
489 f: F,
490 ) -> impl Iterator<Item = Result<B, E>> + 'a
491 where
492 I: Iterator<Item = Result<A, E>> + 'a,
493 F: Fn(A) -> Result<Option<B>, E> + 'a,
494 {
495 iter.filter_map(move |result| match result {
496 Ok(node) => f(node).transpose(),
497 Err(e) => Some(Err(e)),
498 })
499 }
General Comments 0
You need to be logged in to leave comments. Login now