🏡 index : ~doyle/stork.git

author Jordan Doyle <jordan@doyle.la> 2020-02-14 5:00:54.0 +00:00:00
committer Jordan Doyle <jordan@doyle.la> 2020-02-14 5:00:54.0 +00:00:00
commit
7761e3d56c0977b4bf6ce9984f6c7ea6f97bbf76 [patch]
tree
c12fb550d0402fc73fa9e34c5b9f91f8ade727e5
parent
7d07f344c29a929e90983211de6eac42d4932993
download
7761e3d56c0977b4bf6ce9984f6c7ea6f97bbf76.tar.gz

#1: Add some basic recursion detection



Diff

 stork/src/lib.rs      | 17 +++++++++++++++--
 stork_http/src/lib.rs |  5 +++++
 2 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/stork/src/lib.rs b/stork/src/lib.rs
index 2e76f33..f9c67a9 100644
--- a/stork/src/lib.rs
+++ b/stork/src/lib.rs
@@ -55,7 +55,7 @@ pub struct Storkable<T: Unpin, C: StorkClient<T>> {
    parent: Option<Arc<Storkable<T, C>>>,
}

impl<'a, T: Unpin + 'a, C: StorkClient<T> + 'a> Storkable<T, C> {
impl<'a, T: Unpin + PartialEq + 'a, C: StorkClient<T> + 'a> Storkable<T, C> {
    /// Instantiates a new [Storkable] from a T, storking can then
    /// begin on the given entrypoint using the [Storkable::exec] method.
    pub fn new(val: T) -> Self {
@@ -108,13 +108,26 @@ impl<'a, T: Unpin + 'a, C: StorkClient<T> + 'a> Storkable<T, C> {
        try_stream! {
            let mut children = this.client.run(this.val());

            while let Some(child) = children.next().await {
            'child: while let Some(child) = children.next().await {
                let child = child.context(StorkError::ClientError)?;

                if !this.filters.matches(&child) {
                    continue;
                }

                // ensure we're not going to cause a recursive loop by
                // checking that the page we're about to yield isn't a
                // parent of it
                // TODO: should this happen before or after we try to
                // TODO: match it against the filters
                let mut current_parent = this.parent();
                while let Some(parent) = current_parent {
                    if parent.value == this.value {
                        continue 'child;
                    }
                    current_parent = parent.parent();
                }

                yield Storkable {
                    value: child,
                    client: Arc::clone(&this.client),
diff --git a/stork_http/src/lib.rs b/stork_http/src/lib.rs
index 30566c2..5de75ef 100644
--- a/stork_http/src/lib.rs
+++ b/stork_http/src/lib.rs
@@ -105,6 +105,11 @@ impl Link {
        self.text.clone()
    }
}
impl PartialEq for Link {
    fn eq(&self, other: &Self) -> bool {
        self.url().as_str() == other.url().as_str()
    }
}
impl std::str::FromStr for Link {
    type Err = failure::Error;