Streamline code
This commit is contained in:
parent
c77b4acbd4
commit
0fee810040
@ -86,17 +86,19 @@ pub trait WithId {
|
||||
fn id(&self) -> &Self::Id;
|
||||
}
|
||||
|
||||
pub struct MergeCollections<ID, T> {
|
||||
pub struct MergeCollections<ID, T, IT> {
|
||||
_id: PhantomData<ID>,
|
||||
_t: PhantomData<T>,
|
||||
_it: PhantomData<IT>,
|
||||
}
|
||||
|
||||
impl<ID, T> MergeCollections<ID, T>
|
||||
impl<ID, T, IT> MergeCollections<ID, T, IT>
|
||||
where
|
||||
ID: Eq + Hash + Clone,
|
||||
T: WithId<Id = ID> + Merge + Ord,
|
||||
IT: IntoIterator<Item = T>,
|
||||
{
|
||||
pub fn merge_iter<IT: IntoIterator<Item = T>>(primary: IT, secondary: IT) -> Vec<T> {
|
||||
pub fn merge_iter(primary: IT, secondary: IT) -> Vec<T> {
|
||||
let primary = primary
|
||||
.into_iter()
|
||||
.map(|item| (item.id().clone(), item))
|
||||
@ -104,7 +106,7 @@ where
|
||||
Self::merge(primary, secondary)
|
||||
}
|
||||
|
||||
pub fn merge<IT: IntoIterator<Item = T>>(mut primary: HashMap<ID, T>, secondary: IT) -> Vec<T> {
|
||||
pub fn merge(mut primary: HashMap<ID, T>, secondary: IT) -> Vec<T> {
|
||||
for secondary_item in secondary {
|
||||
if let Some(ref mut primary_item) = primary.get_mut(secondary_item.id()) {
|
||||
primary_item.merge_in_place(secondary_item);
|
||||
|
Loading…
Reference in New Issue
Block a user