#[non_exhaustive]pub struct TargetExpr<'a> {
pub address: &'a str,
pub ports: Option<&'a str>,
}Expand description
A target expression split into the part that says what and the part that says where on it.
Borrows from the token it was parsed out of, so splitting a large file costs no allocation.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.address: &'a strThe address expression: a literal, a range, a CIDR block, a keyword or a
hostname, carrying its %zone suffix if it had one. Brackets, if there
were any, are stripped.
ports: Option<&'a str>The port specification as written, if the expression carried one.
Implementations§
Source§impl<'a> TargetExpr<'a>
impl<'a> TargetExpr<'a>
Sourcepub fn parse(token: &'a str) -> Result<Self, TargetParseError>
pub fn parse(token: &'a str) -> Result<Self, TargetParseError>
Splits one token.
Surrounding whitespace is trimmed. The halves are not validated here; the grammars that own them check them when the expression is built into targets.
§Examples
use zond_engine::model::parse::target::TargetExpr;
let bare = TargetExpr::parse("192.0.2.1").unwrap();
assert_eq!(bare.address, "192.0.2.1");
assert_eq!(bare.ports, None);
let with_ports = TargetExpr::parse("[2001:db8::1]:443").unwrap();
assert_eq!(with_ports.address, "2001:db8::1");
assert_eq!(with_ports.ports, Some("443"));
// A bare IPv6 address is an address, never an address and a port.
let ambiguous = TargetExpr::parse("2001:db8::1:80").unwrap();
assert_eq!(ambiguous.address, "2001:db8::1:80");
assert_eq!(ambiguous.ports, None);Sourcepub fn addresses(&self) -> impl Iterator<Item = &'a str>
pub fn addresses(&self) -> impl Iterator<Item = &'a str>
The addresses the expression names, splitting the address half on commas.
A comma separates addresses in the address half and is part of the
specification in the port half: 192.0.2.1:80,443 is one host on two ports,
192.0.2.1,192.0.2.2:80 two hosts on one.
Empty fields are skipped, so a trailing comma is not an error.
Trait Implementations§
Source§impl<'a> Clone for TargetExpr<'a>
impl<'a> Clone for TargetExpr<'a>
impl<'a> Copy for TargetExpr<'a>
Source§impl<'a> Debug for TargetExpr<'a>
impl<'a> Debug for TargetExpr<'a>
impl<'a> Eq for TargetExpr<'a>
Source§impl<'a> Hash for TargetExpr<'a>
impl<'a> Hash for TargetExpr<'a>
Source§impl<'a> PartialEq for TargetExpr<'a>
impl<'a> PartialEq for TargetExpr<'a>
impl<'a> StructuralPartialEq for TargetExpr<'a>
Auto Trait Implementations§
impl<'a> Freeze for TargetExpr<'a>
impl<'a> RefUnwindSafe for TargetExpr<'a>
impl<'a> Send for TargetExpr<'a>
impl<'a> Sync for TargetExpr<'a>
impl<'a> Unpin for TargetExpr<'a>
impl<'a> UnsafeUnpin for TargetExpr<'a>
impl<'a> UnwindSafe for TargetExpr<'a>
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
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§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
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> ⓘ
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> ⓘ
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