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
impl ExtractorBuilder
Sourcepub fn new() -> Self
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()?;Sourcepub fn ipv4(&mut self, include: bool) -> &mut Self
pub fn ipv4(&mut self, include: bool) -> &mut Self
Enable or disable IPv4 address extraction.
Default: true
Sourcepub fn ipv6(&mut self, include: bool) -> &mut Self
pub fn ipv6(&mut self, include: bool) -> &mut Self
Enable or disable IPv6 address extraction.
Default: true
Sourcepub fn private_ips(&mut self, include: bool) -> &mut Self
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
Sourcepub fn loopback_ips(&mut self, include: bool) -> &mut Self
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
Sourcepub fn broadcast_ips(&mut self, include: bool) -> &mut Self
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
Sourcepub fn ignore_private(&mut self) -> &mut Self
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)
Sourcepub fn ignore_loopback(&mut self) -> &mut Self
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
Sourcepub fn ignore_broadcast(&mut self) -> &mut Self
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
Sourcepub fn only_public(&mut self) -> &mut Self
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()?;