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
+1 -1
View File
@@ -1,7 +1,7 @@
use derive_more::{Deref, DerefMut, From, IntoIterator};
use itertools::Itertools;
use serde::{Deserialize, Serialize};
use crate::dns::utils::MapTryInto;
use crate::utils::MapTryInto;
pub trait MessageModel<Message: prost::Message>: Into<Message> + for<'m> TryFrom<&'m Message> {}
+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)
}
}