diff --git a/src/domains.rs b/src/domains.rs index c618a61..4585284 100644 --- a/src/domains.rs +++ b/src/domains.rs @@ -192,12 +192,12 @@ pub(crate) fn find_authority_end( } } - return (end, last_dot); + (end, last_dot) } else { - return (None, None); + (None, None) } } else { - return (end, last_dot); + (end, last_dot) } } diff --git a/src/finder.rs b/src/finder.rs index 67854f9..e4bb7e2 100644 --- a/src/finder.rs +++ b/src/finder.rs @@ -102,12 +102,14 @@ pub struct LinkFinder { url_can_be_iri: bool, } +type TriggerFinder = dyn Fn(&[u8]) -> Option; + /// Iterator for finding links. pub struct Links<'t> { text: &'t str, rewind: usize, - trigger_finder: Box Option>, + trigger_finder: Box, email_scanner: EmailScanner, url_scanner: UrlScanner, domain_scanner: DomainScanner, @@ -232,7 +234,7 @@ impl<'t> Links<'t> { }; // With optional schemes URLs don't have unique `:`, then search for `.` as well - let trigger_finder: Box Option> = match (url, email) { + let trigger_finder: Box = match (url, email) { (true, true) if url_must_have_scheme => Box::new(|s| memchr2(b':', b'@', s)), (true, true) => Box::new(|s| memchr3(b':', b'@', b'.', s)), (true, false) if url_must_have_scheme => Box::new(|s| memchr(b':', s)), @@ -271,7 +273,7 @@ impl<'t> Iterator for Links<'t> { let end = self.rewind + range.end; self.rewind = end; let link = Link { - text: &self.text, + text: self.text, start, end, kind, @@ -299,10 +301,10 @@ impl<'t> Iterator for Spans<'t> { fn next(&mut self) -> Option> { match self.links.peek() { - Some(ref link) => { + Some(link) => { if self.position < link.start { let span = Span { - text: &self.text, + text: self.text, start: self.position, end: link.start, kind: None, @@ -314,7 +316,7 @@ impl<'t> Iterator for Spans<'t> { None => { if self.position < self.text.len() { let span = Span { - text: &self.text, + text: self.text, start: self.position, end: self.text.len(), kind: None, @@ -327,7 +329,7 @@ impl<'t> Iterator for Spans<'t> { self.links.next().map(|link| { self.position = link.end; Span { - text: &self.text, + text: self.text, start: link.start, end: link.end, kind: Some(link.kind), diff --git a/src/url.rs b/src/url.rs index 2907868..3f106e9 100644 --- a/src/url.rs +++ b/src/url.rs @@ -9,7 +9,7 @@ use crate::scanner::Scanner; /// The shortest valid URL (without a scheme) might be g.cn (Google China), /// which consists of four characters. /// We set this as a lower threshold for parsing URLs from plaintext -/// to avoid false-positives and as a slight performance optimization. +/// to avoid false positives and as a slight performance optimization. /// This threshold might be adjusted in the future. const MIN_URL_LENGTH: usize = 4; @@ -146,10 +146,7 @@ fn find_scheme_start(s: &str) -> (Option, Option) { /// /// We could make this configurable, but let's keep it simple until someone asks (hi!). fn scheme_requires_host(scheme: &str) -> bool { - match scheme { - "https" | "http" | "ftp" | "ssh" => true, - _ => false, - } + matches!(scheme, "https" | "http" | "ftp" | "ssh") } /// Find the start of a plain domain URL (no scheme), e.g. from `blog.`, start at `g` and end at `b`. @@ -175,7 +172,7 @@ fn find_domain_start(s: &str, iri_parsing_enabled: bool) -> (Option, Opti // If this was a valid domain, we'd have extracted it already from the previous "." '.' => return (None, None), '-' => { - if first == None { + if first.is_none() { // Domain label can't end with `-` return (None, None); } else {