utils: add MapTryInto

This commit is contained in:
Luna Yao committed 2026-04-06 11:54:01 +02:00
1 parent de84adb3a6
commit 863fc6f4cc
2 files changed
+14 -1

No files matched your search

+13
View File
@@ -161,3 +161,16 @@ pub trait DeterministicDigest: Serialize {
}
impl<S: Serialize> DeterministicDigest for S {}
pub trait MapTryInto<S> {
fn map_try_into<T: TryFrom<S>>(self) -> impl Iterator<Item = Result<T, T::Error>>;
}
impl<I, S> MapTryInto<S> for I
where
I: IntoIterator<Item = S>,
{
fn map_try_into<T: TryFrom<S>>(self) -> impl Iterator<Item = Result<T, T::Error>> {
self.into_iter().map(T::try_from)
}
}