utils: add MapTryInto

This commit is contained in:
Luna Yao
2026-02-20 16:18:48 +01:00
parent de84adb3a6
commit 863fc6f4cc
2 changed files with 14 additions and 1 deletions
+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)
}
}