pub struct PortSet { /* private fields */ }Expand description
A collection of TCP and UDP port ranges used for target discovery.
Under the hood, this stores disjoint ranges. Upon creation, all ranges
are merged and sorted (canonicalized) to ensure O(log N) lookup times
via binary search.
Implementations§
Source§impl PortSet
impl PortSet
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the total number of unique port/protocol combinations.
Note: This counts every individual port within every range.
Sourcepub fn iter(&self) -> impl Iterator<Item = (u16, Protocol)> + '_
pub fn iter(&self) -> impl Iterator<Item = (u16, Protocol)> + '_
Returns an iterator over all individual ports in the set.
Yields TCP ports first, followed by UDP ports.
Sourcepub fn to_vec(&self) -> Vec<(u16, Protocol)>
pub fn to_vec(&self) -> Vec<(u16, Protocol)>
Flattens the set into a vector of individual ports.
Trait Implementations§
impl Eq for PortSet
impl StructuralPartialEq for PortSet
Source§impl TryFrom<&str> for PortSet
impl TryFrom<&str> for PortSet
Source§fn try_from(value: &str) -> Result<Self, Self::Error>
fn try_from(value: &str) -> Result<Self, Self::Error>
Parses a string into a canonicalized PortSet.
§Format Support
- Individual:
80,443 - Ranges:
1000-2000 - Protocols: Defaults to TCP. Use
u:prefix for UDP (e.g.,u:53). - Mixed:
80, 443, u:53, 161-162
§Examples
use zond_engine::core::models::port::set::PortSet;
let set = PortSet::try_from("80, u:53, 1000-1005").unwrap();
assert!(set.has_tcp(80));
assert!(set.has_udp(53));
assert_eq!(set.len(), 8); // 1 + 1 + 6Source§type Error = PortSetParseError
type Error = PortSetParseError
The type returned in the event of a conversion error.
Auto Trait Implementations§
impl Freeze for PortSet
impl RefUnwindSafe for PortSet
impl Send for PortSet
impl Sync for PortSet
impl Unpin for PortSet
impl UnsafeUnpin for PortSet
impl UnwindSafe for PortSet
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more