Skip to main content

Extractor

Struct Extractor 

Source
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

Source

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.

Trait Implementations§

Source§

impl Debug for Extractor

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.