Skip to content

Commit

Permalink
Add PhantomData field
Browse files Browse the repository at this point in the history
  • Loading branch information
Philippe-Cholet committed Jun 12, 2023
1 parent d8bdac5 commit 5eb0eb5
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/merge_join.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::cmp::Ordering;
use std::iter::Fuse;
use std::fmt;
use std::marker::PhantomData;

use either::Either;

Expand All @@ -10,7 +11,7 @@ use crate::size_hint::{self, SizeHint};
#[cfg(doc)]
use crate::Itertools;

pub trait MergePredicate<I, J, T>: FnMut(&I, &J) -> T {
pub trait MergePredicate<I, J, T> {
type Item;
fn left(left: I) -> Self::Item;
fn right(right: J) -> Self::Item;
Expand All @@ -31,21 +32,19 @@ pub fn merge_join_by<I, J, F, T>(left: I, right: J, cmp_fn: F)
left: put_back(left.into_iter().fuse()),
right: put_back(right.into_iter().fuse()),
cmp_fn,
_t: PhantomData,
}
}

/// An iterator adaptor that merge-joins items from the two base iterators in ascending order.
///
/// See [`.merge_join_by()`](crate::Itertools::merge_join_by) for more information.
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
pub struct MergeJoinBy<I, J, F, T>
where I: Iterator,
J: Iterator,
F: FnMut(&I::Item, &J::Item) -> T,
{
pub struct MergeJoinBy<I: Iterator, J: Iterator, F, T> {
left: PutBack<Fuse<I>>,
right: PutBack<Fuse<J>>,
cmp_fn: F
cmp_fn: F,
_t: PhantomData<T>,
}

impl<I, J, F: FnMut(&I, &J) -> Ordering> MergePredicate<I, J, Ordering> for F {
Expand Down Expand Up @@ -112,17 +111,16 @@ impl<I, J, F, T> Clone for MergeJoinBy<I, J, F, T>
J: Iterator,
PutBack<Fuse<I>>: Clone,
PutBack<Fuse<J>>: Clone,
F: FnMut(&I::Item, &J::Item) -> T + Clone,
F: Clone,
{
clone_fields!(left, right, cmp_fn);
clone_fields!(left, right, cmp_fn, _t);
}

impl<I, J, F, T> fmt::Debug for MergeJoinBy<I, J, F, T>
where I: Iterator + fmt::Debug,
I::Item: fmt::Debug,
J: Iterator + fmt::Debug,
J::Item: fmt::Debug,
F: FnMut(&I::Item, &J::Item) -> T,
{
debug_fmt_fields!(MergeJoinBy, left, right);
}
Expand Down

0 comments on commit 5eb0eb5

Please sign in to comment.