revset: add method to upcast InternalRevset to ToPredicateFn

This commit is contained in:
Yuya Nishihara 2023-04-01 22:07:14 +09:00
parent 426f3e4e0a
commit 69794f2585

View file

@ -48,6 +48,10 @@ impl<T: ToPredicateFn + ?Sized> ToPredicateFn for Box<T> {
trait InternalRevset<'index>: fmt::Debug + ToPredicateFn {
// All revsets currently iterate in order of descending index position
fn iter(&self) -> Box<dyn Iterator<Item = IndexEntry<'index>> + '_>;
fn into_predicate<'a>(self: Box<Self>) -> Box<dyn ToPredicateFn + 'a>
where
Self: 'a;
}
pub struct RevsetImpl<'index> {
@ -215,6 +219,13 @@ impl<'index> InternalRevset<'index> for EagerRevset<'index> {
fn iter(&self) -> Box<dyn Iterator<Item = IndexEntry<'index>> + '_> {
Box::new(self.index_entries.iter().cloned())
}
fn into_predicate<'a>(self: Box<Self>) -> Box<dyn ToPredicateFn + 'a>
where
Self: 'a,
{
self
}
}
impl ToPredicateFn for EagerRevset<'_> {
@ -240,6 +251,13 @@ where
fn iter(&self) -> Box<dyn Iterator<Item = IndexEntry<'index>> + '_> {
Box::new(self.walk.clone())
}
fn into_predicate<'a>(self: Box<Self>) -> Box<dyn ToPredicateFn + 'a>
where
Self: 'a,
{
self
}
}
impl<'index, T> ToPredicateFn for RevWalkRevset<T>
@ -286,6 +304,13 @@ impl<'index> InternalRevset<'index> for ChildrenRevset<'index> {
.any(|parent_pos| roots.contains(parent_pos))
}))
}
fn into_predicate<'a>(self: Box<Self>) -> Box<dyn ToPredicateFn + 'a>
where
Self: 'a,
{
self
}
}
impl ToPredicateFn for ChildrenRevset<'_> {
@ -306,6 +331,13 @@ impl<'index, P: ToPredicateFn> InternalRevset<'index> for FilterRevset<'index, P
let p = self.predicate.to_predicate_fn();
Box::new(self.candidates.iter().filter(p))
}
fn into_predicate<'a>(self: Box<Self>) -> Box<dyn ToPredicateFn + 'a>
where
Self: 'a,
{
self
}
}
impl<P: ToPredicateFn> ToPredicateFn for FilterRevset<'_, P> {
@ -330,6 +362,13 @@ impl<'index> InternalRevset<'index> for UnionRevset<'index> {
iter2: self.set2.iter().peekable(),
})
}
fn into_predicate<'a>(self: Box<Self>) -> Box<dyn ToPredicateFn + 'a>
where
Self: 'a,
{
self
}
}
impl ToPredicateFn for UnionRevset<'_> {
@ -383,6 +422,13 @@ impl<'index> InternalRevset<'index> for IntersectionRevset<'index> {
iter2: self.set2.iter().peekable(),
})
}
fn into_predicate<'a>(self: Box<Self>) -> Box<dyn ToPredicateFn + 'a>
where
Self: 'a,
{
self
}
}
impl ToPredicateFn for IntersectionRevset<'_> {
@ -448,6 +494,13 @@ impl<'index> InternalRevset<'index> for DifferenceRevset<'index> {
iter2: self.set2.iter().peekable(),
})
}
fn into_predicate<'a>(self: Box<Self>) -> Box<dyn ToPredicateFn + 'a>
where
Self: 'a,
{
self
}
}
impl ToPredicateFn for DifferenceRevset<'_> {