Struct Domain
pub struct Domain(/* private fields */);net only.Expand description
A domain.
§Remarks
The validation of domains created by this type is very shallow. Proper validation is offloaded to other services such as DNS resolvers.
Implementations§
§impl Domain
impl Domain
pub const fn from_static(s: &'static str) -> Domain
pub const fn from_static(s: &'static str) -> Domain
Creates a domain at compile time.
This function requires the static string to be a valid domain
§Panics
This function panics at compile time when the static string is not a valid domain.
pub const fn tld_private() -> Domain
pub const fn tld_private() -> Domain
Create an new apex Domain (TLD) meant for loopback purposes.
As proposed in https://itp.cdn.icann.org/en/files/security-and-stability-advisory-committee-ssac-reports/sac-113-en.pdf.
In specific this means that it will match on any domain with the TLD .internal.
pub const fn tld_localhost() -> Domain
pub const fn tld_localhost() -> Domain
Creates the localhost Domain.
pub fn is_wildcard(&self) -> bool
pub fn is_wildcard(&self) -> bool
Returns true if this domain is a wildcard domain (i.e. its leftmost
label is "*").
Label-based — agrees with Self::as_wildcard_parent for inputs like
".*.example.com" where a leading FQDN dot precedes the wildcard.
pub fn is_tld(&self) -> bool
pub fn is_tld(&self) -> bool
Returns true if this domain is Top-Level Domain (TLD).
Note that we consider a country-level TLD (ccTLD) such as org.uk
also a TLD. That is we consider any ccTLD also TLD. While
not technically correct, in practice it is at least for the purposes
that we are aware of a non-meaningful distinction to make.
§Example
use rama_net::address::Domain;
assert!(Domain::from_static("com").is_tld());
assert!(Domain::from_static(".com").is_tld());
assert!(Domain::from_static("co.uk").is_tld());
assert!(!Domain::from_static("example.com").is_tld());
assert!(!Domain::from_static("example.co.uk").is_tld());pub fn is_sld(&self) -> bool
pub fn is_sld(&self) -> bool
Returns true if this domain is Second-Level Domain (SLD).
§Example
use rama_net::address::Domain;
assert!(!Domain::from_static("com").is_sld());
assert!(!Domain::from_static(".com").is_sld());
assert!(!Domain::from_static("co.uk").is_sld());
assert!(!Domain::from_static(".co.uk").is_sld());
assert!(Domain::from_static(".example.com").is_sld());
assert!(Domain::from_static(".example.co.uk").is_sld());
assert!(!Domain::from_static("foo.example.com").is_sld());
assert!(!Domain::from_static("foo.example.co.uk").is_sld());pub fn as_wildcard_parent(&self) -> Option<Domain>
pub fn as_wildcard_parent(&self) -> Option<Domain>
Returns the parent of this wildcard domain, or None if self is not
a wildcard.
Equivalent to DomainLabels::parent when Self::is_wildcard.
Use Self::is_wildcard alone if you only need the predicate; it
doesn’t allocate.
pub fn try_as_sub(&self, sub: impl AsDomainRef) -> Result<Domain, PushError>
pub fn try_as_sub(&self, sub: impl AsDomainRef) -> Result<Domain, PushError>
Try to create a subdomain from the current Domain with the given
subdomain prefixed to it.
§Errors
Returns PushError if any segment of sub is not a valid label or
the combined name would exceed MAX_NAME_LEN.
pub fn try_as_wildcard(&self) -> Result<Domain, PushError>
pub fn try_as_wildcard(&self) -> Result<Domain, PushError>
Promote this Domain to a wildcard.
E.g. turn example.com in *.example.com.
§Errors
Returns PushError if the resulting name would exceed
MAX_NAME_LEN.
pub fn strip_sub(&self, prefix: impl AsDomainRef) -> Option<Domain>
pub fn strip_sub(&self, prefix: impl AsDomainRef) -> Option<Domain>
Try to strip the subdomain (prefix) from the current domain.
prefix is matched label-by-label, case-insensitively. Returns
Some(remainder) if every label of prefix matches the corresponding
leftmost label of self and at least one label remains; otherwise
None.
§Behavior note
Prior to the move to label-based matching, this performed a raw
case-sensitive string strip_prefix. The current implementation is
label-aware and case-insensitive, which is consistent with the rest
of the type (Eq/Hash/Ord are also case-insensitive).
pub fn is_sub_of(&self, other: &Domain) -> bool
pub fn is_sub_of(&self, other: &Domain) -> bool
Returns true if self is a sub-domain of (or equal to) other.
Pure delegation to DomainLabels::is_subdomain_of; kept as an
inherent method for source-compat.
pub fn is_parent_of(&self, other: &Domain) -> bool
pub fn is_parent_of(&self, other: &Domain) -> bool
Returns true if self is a parent of (or equal to) other.
pub fn have_same_registrable_domain(&self, other: &Domain) -> bool
pub fn have_same_registrable_domain(&self, other: &Domain) -> bool
Compare the registrable domain
§Example
use rama_net::address::Domain;
assert!(Domain::from_static("www.example.com")
.have_same_registrable_domain(&Domain::from_static("example.com")));
assert!(Domain::from_static("example.com")
.have_same_registrable_domain(&Domain::from_static("www.example.com")));
assert!(Domain::from_static("a.example.com")
.have_same_registrable_domain(&Domain::from_static("b.example.com")));
assert!(Domain::from_static("example.com")
.have_same_registrable_domain(&Domain::from_static("example.com")));Trait Implementations§
§impl AsDomainRef for Domain
impl AsDomainRef for Domain
fn as_wildcard_parent(&self) -> Option<Domain>
§impl<'de> Deserialize<'de> for Domain
impl<'de> Deserialize<'de> for Domain
§fn deserialize<D>(
deserializer: D,
) -> Result<Domain, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<Domain, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
§impl DomainLabels for Domain
impl DomainLabels for Domain
§fn parent(&self) -> Option<Domain>
fn parent(&self) -> Option<Domain>
Domain-specialized fast path: slices the underlying buffer instead
of collecting labels into a Vec and join-ing them.
§type LabelIter<'a> = DomainLabelIter<'a>
type LabelIter<'a> = DomainLabelIter<'a>
self, yielded most-specific-first
("www.example.com".labels() yields www, example, com).§fn labels(&self) -> <Domain as DomainLabels>::LabelIter<'_>
fn labels(&self) -> <Domain as DomainLabels>::LabelIter<'_>
self.§fn label_count(&self) -> usize
fn label_count(&self) -> usize
§fn starts_with<D>(&self, prefix: &D) -> boolwhere
D: DomainLabels + ?Sized,
fn starts_with<D>(&self, prefix: &D) -> boolwhere
D: DomainLabels + ?Sized,
§fn is_subdomain_of<D>(&self, parent: &D) -> boolwhere
D: DomainLabels + ?Sized,
fn is_subdomain_of<D>(&self, parent: &D) -> boolwhere
D: DomainLabels + ?Sized,
§fn suffix_iter(&self) -> SuffixIter<'_, Self> ⓘwhere
Self: Sized,
fn suffix_iter(&self) -> SuffixIter<'_, Self> ⓘwhere
Self: Sized,
self and each successive parent, ending just before the
empty domain. For "a.b.c" yields "a.b.c", "b.c", "c".§impl From<Domain> for ForwardedAuthority
impl From<Domain> for ForwardedAuthority
§fn from(value: Domain) -> ForwardedAuthority
fn from(value: Domain) -> ForwardedAuthority
§impl Ord for Domain
impl Ord for Domain
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
§impl PartialOrd<&str> for Domain
impl PartialOrd<&str> for Domain
§impl PartialOrd<Domain> for &str
impl PartialOrd<Domain> for &str
§impl PartialOrd<Domain> for String
impl PartialOrd<Domain> for String
§impl PartialOrd<Domain> for str
impl PartialOrd<Domain> for str
§impl PartialOrd<String> for Domain
impl PartialOrd<String> for Domain
§impl PartialOrd<str> for Domain
impl PartialOrd<str> for Domain
§impl PartialOrd for Domain
impl PartialOrd for Domain
§impl Serialize for Domain
impl Serialize for Domain
§fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
§impl TraceField for Domain
impl TraceField for Domain
fn field_type() -> FieldType
§fn encode<W>(&self, enc: &mut EventEncoder<'_, W>) -> Result<(), Error>where
W: Write,
fn encode<W>(&self, enc: &mut EventEncoder<'_, W>) -> Result<(), Error>where
W: Write,
§fn decode_ref<'a>(
val: &FieldValueRef<'a>,
) -> Option<<Domain as TraceField>::Ref<'a>>
fn decode_ref<'a>( val: &FieldValueRef<'a>, ) -> Option<<Domain as TraceField>::Ref<'a>>
§fn is_optional() -> bool
fn is_optional() -> bool
§fn decode_missing<'a>() -> Option<Self::Ref<'a>>
fn decode_missing<'a>() -> Option<Self::Ref<'a>>
None for required fields (decode failure) and Some(None) for
optional fields.impl Eq for Domain
impl IntoDomain for Domain
Auto Trait Implementations§
impl Freeze for Domain
impl RefUnwindSafe for Domain
impl Send for Domain
impl Sync for Domain
impl Unpin for Domain
impl UnsafeUnpin for Domain
impl UnwindSafe for Domain
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§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,
§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§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§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a rama_grpc::Request§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§fn and<P, B, E>(self, other: P) -> And<T, P>
fn and<P, B, E>(self, other: P) -> And<T, P>
Policy that returns Action::Follow only if self and other return
Action::Follow. Read more§impl<T, U> RamaTryFrom<T> for Uwhere
U: TryFrom<T>,
impl<T, U> RamaTryFrom<T> for Uwhere
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
fn rama_try_from(value: T) -> Result<U, <U as RamaTryFrom<T>>::Error>
§impl<T, U, CrateMarker> RamaTryInto<U, CrateMarker> for Twhere
U: RamaTryFrom<T, CrateMarker>,
impl<T, U, CrateMarker> RamaTryInto<U, CrateMarker> for Twhere
U: RamaTryFrom<T, CrateMarker>,
type Error = <U as RamaTryFrom<T, CrateMarker>>::Error
fn rama_try_into(self) -> Result<U, <U as RamaTryFrom<T, CrateMarker>>::Error>
§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.
§impl<V, F> ValueFormatter<&V> for F
impl<V, F> ValueFormatter<&V> for F
§fn format_value(writer: impl ValueWriter, value: &&V)
fn format_value(writer: impl ValueWriter, value: &&V)
value to writer§impl<V, F> ValueFormatter<Arc<V>> for F
impl<V, F> ValueFormatter<Arc<V>> for F
§fn format_value(writer: impl ValueWriter, value: &Arc<V>)
fn format_value(writer: impl ValueWriter, value: &Arc<V>)
value to writer§impl<V, F> ValueFormatter<Box<V>> for F
impl<V, F> ValueFormatter<Box<V>> for F
§fn format_value(writer: impl ValueWriter, value: &Box<V>)
fn format_value(writer: impl ValueWriter, value: &Box<V>)
value to writer§impl<V, F> ValueFormatter<Cow<'_, V>> for F
impl<V, F> ValueFormatter<Cow<'_, V>> for F
§fn format_value(writer: impl ValueWriter, value: &Cow<'_, V>)
fn format_value(writer: impl ValueWriter, value: &Cow<'_, V>)
value to writer§impl<V, F> ValueFormatter<Option<V>> for Fwhere
F: ValueFormatter<V> + ?Sized,
impl<V, F> ValueFormatter<Option<V>> for Fwhere
F: ValueFormatter<V> + ?Sized,
§fn format_value(writer: impl ValueWriter, value: &Option<V>)
fn format_value(writer: impl ValueWriter, value: &Option<V>)
value to writer