mirror of
https://github.com/EasyTier/EasyTier.git
synced 2026-08-07 04:59:49 +00:00
utils: add MapTryInto
This commit is contained in:
@@ -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> {}
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user