linkify
Rust library that finds URLs and email addresses in plain text with correct boundaries.
Repository Health
Technical Analysis
Linkify is a Rust library for finding links, such as URLs and email addresses, inside plain text. Rather than relying on a brittle regular expression, it performs a linear scan that is careful about where a link actually ends, correctly handling trailing dots and commas, balanced and unbalanced parentheses, angle brackets, Unicode, Punycode, and emoji.
The API centers on a configurable finder that yields spans for each detected link, letting callers extract or rewrite links (for example, turning them into anchor tags). With a single lightweight dependency and linear runtime, it is well suited to processing user-generated content, chat messages, and documents.
What You Get
- A LinkFinder that yields spans with start, end, and link kind for each match
- Correct boundary handling for trailing punctuation, parentheses, and angle brackets
- Unicode, Punycode, and emoji-aware URL detection
- Options to restrict to URLs, emails, or both, and to require a scheme
- Linear-time scanning backed by a single small dependency (memchr)
Common Use Cases
- Auto-linking URLs and emails in user-generated content or chat messages
- Extracting all links from a document for validation or crawling
- Highlighting or rewriting links when rendering plain text as HTML
Under The Hood
Architecture - The crate exposes a LinkFinder (src/finder.rs) that drives per-kind scanners: src/url.rs and src/email.rs implement the boundary logic, with src/domains.rs and src/scanner.rs providing shared domain and character scanning. A single linear pass produces Link spans rather than backtracking. Tech Stack - Pure Rust (edition 2018), dual-licensed MIT/Apache-2.0, with memchr as its only runtime dependency; criterion and doc-comment are dev-only. A WebAssembly demo lives under demo/ and fuzz targets under fuzz/. Code Quality - The repo has an extensive tests/ suite, criterion benches, a fuzzing harness, and a CHANGELOG, reflecting careful attention to the many boundary edge cases described in the README. API Design - The public surface is minimal and discoverable: construct a LinkFinder, optionally configure kinds and scheme requirements, then iterate links over any string slice, keeping boilerplate near zero.