Skip to main content

ExtractorBuilder

Struct ExtractorBuilder 

Source
pub struct ExtractorBuilder { /* private fields */ }
Expand description

A builder for configuring IP extraction behavior.

Use ExtractorBuilder to specify which types of IP addresses should be extracted. By default, it extracts both IPv4 and IPv6 but excludes private, loopback, and broadcast addresses.

§Example

use ip_extract::ExtractorBuilder;

let extractor = ExtractorBuilder::new()
    .ipv4(true)
    .ipv6(false)  // Only IPv4
    .private_ips(true)  // Include private ranges
    .build()?;

Implementations§

Source§

impl ExtractorBuilder

Source

pub fn new() -> Self

Create a new builder with default settings.

By default, all IP addresses are extracted (principle of least surprise). Use .only_public() or .ignore_*() methods to filter specific categories.

Defaults:

  • IPv4: enabled
  • IPv6: enabled
  • Private IPs: enabled (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, fc00::/7)
  • Loopback IPs: enabled (127.0.0.0/8, ::1)
  • Broadcast IPs: enabled (255.255.255.255, link-local)
§Examples
use ip_extract::ExtractorBuilder;

// Extract all IPs (default)
let extractor = ExtractorBuilder::new().build()?;

// Extract only public IPs
let extractor = ExtractorBuilder::new().only_public().build()?;

// Granular control
let extractor = ExtractorBuilder::new()
    .ignore_private()
    .ignore_loopback()
    .build()?;
Source

pub fn ipv4(&mut self, include: bool) -> &mut Self

Enable or disable IPv4 address extraction.

Default: true

Source

pub fn ipv6(&mut self, include: bool) -> &mut Self

Enable or disable IPv6 address extraction.

Default: true

Source

pub fn private_ips(&mut self, include: bool) -> &mut Self

Include private IP addresses (RFC 1918 for IPv4, ULA for IPv6).

Private ranges include:

  • IPv4: 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16
  • IPv6: fc00::/7 (ULA), fe80::/10 (link-local)

Default: true

Source

pub fn loopback_ips(&mut self, include: bool) -> &mut Self

Include loopback addresses.

Loopback ranges:

  • IPv4: 127.0.0.0/8
  • IPv6: ::1

Default: true

Source

pub fn broadcast_ips(&mut self, include: bool) -> &mut Self

Include broadcast addresses.

Covers:

  • IPv4: 255.255.255.255 and link-local (169.254.0.0/16)
  • IPv6: link-local and other special ranges

Default: true

Source

pub fn ignore_private(&mut self) -> &mut Self

Ignore private IP addresses (convenience for .private_ips(false)).

Excludes:

  • IPv4: 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16
  • IPv6: fc00::/7 (ULA), fe80::/10 (link-local)
Source

pub fn ignore_loopback(&mut self) -> &mut Self

Ignore loopback addresses (convenience for .loopback_ips(false)).

Excludes:

  • IPv4: 127.0.0.0/8
  • IPv6: ::1
Source

pub fn ignore_broadcast(&mut self) -> &mut Self

Ignore broadcast addresses (convenience for .broadcast_ips(false)).

Excludes:

  • IPv4: 255.255.255.255 and link-local (169.254.0.0/16)
  • IPv6: link-local and other special ranges
Source

pub fn only_public(&mut self) -> &mut Self

Extract only publicly routable IP addresses.

This is a convenience method equivalent to:

builder
    .ignore_private()
    .ignore_loopback()
    .ignore_broadcast();

Excludes:

  • Private: RFC 1918 (IPv4), ULA (IPv6)
  • Loopback: 127.0.0.0/8, ::1
  • Broadcast: 255.255.255.255, link-local ranges
§Example
use ip_extract::ExtractorBuilder;

let extractor = ExtractorBuilder::new()
    .only_public()
    .build()?;
Source

pub fn build(&self) -> Result<Extractor>

Build and return an Extractor with the configured settings.

§Errors

Returns an error if no IP version (IPv4 or IPv6) is enabled. At least one must be selected.

§Example
use ip_extract::ExtractorBuilder;

let extractor = ExtractorBuilder::new()
    .ipv4(true)
    .ipv6(true)
    .build()?;

Trait Implementations§

Source§

impl Default for ExtractorBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. 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.