From 1b69b24a8f8aa604f999390c56a7d9f7be70bfbd Mon Sep 17 00:00:00 2001 From: Jordan Doyle Date: Wed, 12 Feb 2020 21:06:27 +0000 Subject: [PATCH] Add a Scheme filter for links --- crawler/src/filters.rs | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/crawler/src/filters.rs b/crawler/src/filters.rs index 3011410..b2dd894 100644 --- a/crawler/src/filters.rs +++ b/crawler/src/filters.rs @@ -33,25 +33,28 @@ impl FilterSet { true } } -impl Default for Filters { +impl Default for FilterSet { + /// Creates an empty filter set. fn default() -> Self { - Filters { - url: None, - } + FilterSet { url: None } } } -#[derive(Clone)] +#[derive(Debug, Clone)] pub enum FilterType { - StartsWith, EndsWith, Contains + StartsWith, + EndsWith, + Contains, } -#[derive(Clone)] +#[derive(Debug, Clone)] pub enum UrlFilterType { - Path(FilterType), Domain + Path(FilterType), + Domain, + Scheme, } -#[derive(Clone)] +#[derive(Debug, Clone)] pub struct UrlFilter { kind: UrlFilterType, value: String, @@ -76,12 +79,13 @@ impl UrlFilter { UrlFilterType::Path(FilterType::StartsWith) => url.path().starts_with(&self.value), UrlFilterType::Path(FilterType::EndsWith) => url.path().ends_with(&self.value), UrlFilterType::Path(FilterType::Contains) => url.path().contains(&self.value), - UrlFilterType::Domain => url.host_str().map_or(false, |v| v == &self.value) + UrlFilterType::Domain => url.host_str().map_or(false, |v| v == &self.value), + UrlFilterType::Scheme => url.scheme() == &self.value, }; match self.negated { true => !matches, - false => matches + false => matches, } } -} \ No newline at end of file +} -- libgit2 1.7.2