# referer-parser-rs
Rust implementation of [snowplow-referer-parser](https://github.com/snowplow-referer-parser/referer-parser). Identifies the source of a HTTP referer URL (search engine, social network, webmail, etc.) and extracts the search term when available.
## Usage
Download the [referers.yml](https://raw.githubusercontent.com/snowplow-referer-parser/referer-parser/master/resources/referers.yml) database, then:
```rust
use referer_parser_rs::Parser;
use url::Url;
let parser = Parser::new("referers.yml").unwrap();
let url = Url::parse("https://www.google.com/search?q=hello+world").unwrap();
if let Some(entry) = parser.lookup(&url) {
println!("{} / {} / {:?}", entry.medium, entry.source, entry.search_term);
// search / Google / Some("hello world")
}
```
## Design
- The YAML database is loaded once into a flat `Vec` of entries, with a `HashMap` mapping each domain (or domain/path) key to an entry index.
- `lookup` returns an `Entry` that borrows from both the `Parser` and the input `Url` -- no heap allocation unless percent-decoding is needed for the search term.
- Domain resolution walks subdomains (`www.google.fr` -> `google.fr`) and path prefixes (`/webmail/fr_FR` -> `/webmail`), preferring path-qualified matches over domain-only matches.