Skip to main content

IpMatch

Struct IpMatch 

Source
pub struct IpMatch<'a> { /* private fields */ }
Expand description

A validated IP address match within a haystack.

Provides zero-copy access to the matched bytes and their position within the original haystack, plus the IP version. Parsing to IpAddr is available via ip() but not cached — callers who look up the same IP repeatedly should cache at a higher level.

Implementations§

Source§

impl<'a> IpMatch<'a>

Source

pub fn as_bytes(&self) -> &'a [u8]

The matched IP address as a byte slice.

Zero-copy: this is a slice directly into the haystack.

Source

pub fn as_str(&self) -> Cow<'a, str>

The clean IP address as a string, with any defang brackets removed.

For normal (fanged) input this is a zero-copy borrow (Cow::Borrowed). For defanged input (e.g. "192.168.1[.]50") this allocates and strips brackets, returning Cow::Owned("192.168.1.50").

This is the right default for MMDB lookups, deduplication, output, and parsing. For the raw matched text (which may contain brackets), use as_matched_str.

Source

pub fn as_matched_str(&self) -> &'a str

The raw matched text as a string slice.

Returns the exact bytes matched in the haystack — for defanged input, this may include bracket characters (e.g. "192.168.1[.]50"). Use as_str when you need the canonical IP form.

Zero-copy: this is a slice directly into the haystack. Safe without UTF-8 validation because all matched characters (digits, hex, ., :, [, ]) are ASCII.

Source

pub fn range(&self) -> Range<usize>

The byte range of this match within the original haystack.

Source

pub fn kind(&self) -> IpKind

Whether this match is IPv4 or IPv6.

Source

pub fn ip(&self) -> IpAddr

Parse the matched bytes into an IpAddr.

Automatically strips defang brackets before parsing — safe to call on both normal and defanged matches. Not cached; callers processing the same IP repeatedly should cache at a higher level.

§Panics

Panics if the validated bytes cannot be parsed as an IP address. This should not happen in practice because matches are validated by the DFA.

Trait Implementations§

Source§

impl<'a> Clone for IpMatch<'a>

Source§

fn clone(&self) -> IpMatch<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for IpMatch<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for IpMatch<'a>

§

impl<'a> RefUnwindSafe for IpMatch<'a>

§

impl<'a> Send for IpMatch<'a>

§

impl<'a> Sync for IpMatch<'a>

§

impl<'a> Unpin for IpMatch<'a>

§

impl<'a> UnsafeUnpin for IpMatch<'a>

§

impl<'a> UnwindSafe for IpMatch<'a>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.