Pull parent check out and start from the current Storkable instead of the parent
Diff
stork/src/lib.rs | 30 ++++++++++++++++++++----------
1 file changed, 20 insertions(+), 10 deletions(-)
@@ -48,7 +48,7 @@ use failure::ResultExt;
#[derive(Debug, Clone)]
pub struct Storkable<T: Unpin, C: StorkClient<T>> {
pub struct Storkable<T: Unpin + PartialEq + Hash, C: StorkClient<T>> {
value: T,
filters: FilterSet<T>,
client: Arc<C>,
@@ -97,6 +97,22 @@ impl<'a, T: Unpin + PartialEq + 'a, C: StorkClient<T> + 'a> Storkable<T, C> {
self.parent.as_ref().map(Arc::as_ref)
}
fn check_parent_is(&self, value: &T) -> bool {
let mut current_parent = Some(self);
while let Some(parent) = current_parent {
if &parent.value == value {
return true;
}
current_parent = parent.parent();
}
false
}
@@ -108,7 +124,7 @@ impl<'a, T: Unpin + PartialEq + 'a, C: StorkClient<T> + 'a> Storkable<T, C> {
try_stream! {
let mut children = this.client.run(this.val());
'child: while let Some(child) = children.next().await {
while let Some(child) = children.next().await {
let child = child.context(StorkError::ClientError)?;
if !this.filters.matches(&child) {
@@ -118,14 +134,8 @@ impl<'a, T: Unpin + PartialEq + 'a, C: StorkClient<T> + 'a> Storkable<T, C> {
let mut current_parent = this.parent();
while let Some(parent) = current_parent {
if parent.value == this.value {
continue 'child;
}
current_parent = parent.parent();
if this.check_parent_is(&child) {
continue;
}
yield Storkable {