pub struct IpMatch<'a> { /* private fields */ }Expand description
Implementations§
Source§impl<'a> IpMatch<'a>
impl<'a> IpMatch<'a>
Sourcepub fn as_bytes(&self) -> &'a [u8] ⓘ
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.
Sourcepub fn as_str(&self) -> Cow<'a, str>
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.
Sourcepub fn as_matched_str(&self) -> &'a str
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.
Sourcepub fn ip(&self) -> IpAddr
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.