Extract the first subdomain label from a host string. `"alice.localhost"` → `Some("alice")` `"alice.atomic.storage"` → `Some("alice")` `"localhost"` → `None`
(host: &str)
| 404 | /// `"alice.atomic.storage"` → `Some("alice")` |
| 405 | /// `"localhost"` → `None` |
| 406 | fn extract_subdomain(host: &str) -> Option<String> { |
| 407 | // Strip port if somehow present (Url should have parsed it out, but be safe). |
| 408 | let host = host.split(':').next().unwrap_or(host); |
| 409 | |
| 410 | let dot_pos = host.find('.')?; |
| 411 | let subdomain = &host[..dot_pos]; |
| 412 | |
| 413 | if subdomain.is_empty() { |
| 414 | return None; |
| 415 | } |
| 416 | |
| 417 | Some(subdomain.to_string()) |
| 418 | } |
| 419 | |
| 420 | #[cfg(test)] |
| 421 | mod tests { |
no test coverage detected