pub struct Extractor { /* private fields */ }Expand description
The main IP address extractor.
An Extractor scans byte slices for IPv4 and/or IPv6 addresses, applying configurable
filters to include or exclude certain address classes (private, loopback, broadcast).
Extractors are best created via ExtractorBuilder and are designed to be reused
across many calls to find_iter for maximum efficiency.
§Bytes vs. Strings
This extractor works directly on byte slices rather than strings. This avoids UTF-8 validation overhead and enables zero-copy scanning of very large inputs.
§Performance
The extractor uses a compile-time DFA (Deterministic Finite Automaton) for O(n) scanning with minimal overhead. See the crate-level documentation for throughput benchmarks.
Implementations§
Source§impl Extractor
impl Extractor
Sourcepub fn find_iter<'a>(
&'a self,
haystack: &'a [u8],
) -> impl Iterator<Item = Range<usize>> + 'a
pub fn find_iter<'a>( &'a self, haystack: &'a [u8], ) -> impl Iterator<Item = Range<usize>> + 'a
Find all IP addresses in a byte slice.
Returns an iterator of byte ranges [start, end) pointing to each IP address found.
Ranges are guaranteed to be valid indices into haystack.
§Example
use ip_extract::ExtractorBuilder;
let extractor = ExtractorBuilder::new().build()?;
let data = b"Log: 192.168.1.1 sent request to 8.8.8.8";
for range in extractor.find_iter(data) {
let ip = std::str::from_utf8(&data[range]).unwrap();
println!("IP: {}", ip);
}§Arguments
haystack- A byte slice to search for IP addresses.
§Returns
An iterator yielding byte ranges for each valid IP address found.