Struct DomainTrie
pub struct DomainTrie<T> { /* private fields */ }net only.Expand description
An efficient radix tree that can be used to match (sub)domains.
Each inserted entry is either an exact entry or a subtree entry, inferred from the input:
"example.com"— exact: matches only the domainexample.comitself."*.example.com"— subtree: matchesexample.comand every name under it (foo.example.com,a.b.example.com, …).
Both modes can coexist at the same name: inserting example.com and
later *.example.com (or vice versa) leaves both values addressable.
Implementations§
§impl<T> DomainTrie<T>
impl<T> DomainTrie<T>
pub fn new() -> DomainTrie<T>
pub fn new() -> DomainTrie<T>
Create a new DomainTrie.
pub fn len(&self) -> usize
pub fn with_insert_domain(
self,
domain: impl AsDomainRef,
value: T,
) -> DomainTrie<T>
pub fn with_insert_domain( self, domain: impl AsDomainRef, value: T, ) -> DomainTrie<T>
Consume self and insert the given domain paired with the input value.
See Self::insert_domain for the matching semantics (wildcard
*.x is stored as subtree at x; plain x is stored as exact).
pub fn insert_domain(
&mut self,
domain: impl AsDomainRef,
value: T,
) -> &mut DomainTrie<T>
pub fn insert_domain( &mut self, domain: impl AsDomainRef, value: T, ) -> &mut DomainTrie<T>
Insert the given domain paired with the input value.
Dispatch:
- If the input is a wildcard (
"*.foo.bar"), the*.prefix is stripped and the value is stored as a subtree entry atfoo.bar— it matchesfoo.barand every domain under it. - Otherwise the value is stored as an exact entry — only the stored name matches.
Inserting at a name that already has a value of the same kind overwrites it. Exact and subtree slots at the same name are independent.
pub fn with_insert_domain_iter<I, S>(
self,
domains: I,
value: T,
) -> DomainTrie<T>
pub fn with_insert_domain_iter<I, S>( self, domains: I, value: T, ) -> DomainTrie<T>
Consume self and insert the given domains paired with the input value.
Each domain is dispatched through Self::insert_domain.
pub fn insert_domain_iter<I, S>(
&mut self,
domains: I,
value: T,
) -> &mut DomainTrie<T>
pub fn insert_domain_iter<I, S>( &mut self, domains: I, value: T, ) -> &mut DomainTrie<T>
Insert the given domains paired with the input value.
pub fn extend<I, S>(&mut self, iter: I) -> &mut DomainTrie<T>
pub fn extend<I, S>(&mut self, iter: I) -> &mut DomainTrie<T>
Extend this DomainTrie with the given pairs.
pub fn is_match(&self, domain: impl AsDomainRef) -> bool
pub fn is_match(&self, domain: impl AsDomainRef) -> bool
Returns true if domain matches at least one entry in this trie.
Cheaper than self.get(domain).is_some() — does not build the
MatchKind::Subtree { apex } payload for subtree hits.
pub fn get_value(&self, domain: impl AsDomainRef) -> Option<&T>
pub fn get_value(&self, domain: impl AsDomainRef) -> Option<&T>
Returns the value for the most-specific entry that matches domain,
without computing the apex for subtree matches.
Cheaper than Self::get when the caller doesn’t need the apex.
Matching rules are identical to get.
pub fn get(&self, domain: impl AsDomainRef) -> Option<DomainMatch<'_, T>>
pub fn get(&self, domain: impl AsDomainRef) -> Option<DomainMatch<'_, T>>
Look up domain and return a DomainMatch describing the most-
specific entry that matches it, along with whether the match was
exact or via a subtree apex.
Matching rules:
- Exact entries match only their stored name.
- Subtree entries match their apex plus every descendant.
For exact-only lookups, use
get(d).filter(|m| matches!(m.kind, MatchKind::Exact)).
pub fn match_exact(&self, domain: impl AsDomainRef) -> Option<&T>
pub fn match_exact(&self, domain: impl AsDomainRef) -> Option<&T>
Returns the value stored for the exact domain (either its
exact slot, or its subtree slot if exact is unset).
Single-key direct lookup — not the same as Self::get, which
walks ancestors.
pub fn is_match_exact(&self, domain: impl AsDomainRef) -> bool
pub fn is_match_exact(&self, domain: impl AsDomainRef) -> bool
Returns true if domain is stored as an exact (or subtree-apex)
entry in this trie.
Shortcut for self.match_exact(domain).is_some().
Trait Implementations§
§impl<T> Clone for DomainTrie<T>where
T: Clone,
impl<T> Clone for DomainTrie<T>where
T: Clone,
§fn clone(&self) -> DomainTrie<T>
fn clone(&self) -> DomainTrie<T>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more§impl<T> Debug for DomainTrie<T>where
T: Debug,
impl<T> Debug for DomainTrie<T>where
T: Debug,
§impl<T> Default for DomainTrie<T>
impl<T> Default for DomainTrie<T>
§fn default() -> DomainTrie<T>
fn default() -> DomainTrie<T>
§impl<R> DnsAddressResolver for DomainTrie<R>where
R: DnsAddressResolver,
impl<R> DnsAddressResolver for DomainTrie<R>where
R: DnsAddressResolver,
§type Error = <R as DnsAddressResolver>::Error
type Error = <R as DnsAddressResolver>::Error
DnsAddressResolver§fn lookup_ipv4(
&self,
domain: Domain,
) -> impl Stream<Item = Result<Ipv4Addr, <DomainTrie<R> as DnsAddressResolver>::Error>> + Send
fn lookup_ipv4( &self, domain: Domain, ) -> impl Stream<Item = Result<Ipv4Addr, <DomainTrie<R> as DnsAddressResolver>::Error>> + Send
§async fn lookup_ipv4_first(
&self,
domain: Domain,
) -> Option<Result<Ipv4Addr, <DomainTrie<R> as DnsAddressResolver>::Error>>
async fn lookup_ipv4_first( &self, domain: Domain, ) -> Option<Result<Ipv4Addr, <DomainTrie<R> as DnsAddressResolver>::Error>>
§async fn lookup_ipv4_rand(
&self,
domain: Domain,
) -> Option<Result<Ipv4Addr, <DomainTrie<R> as DnsAddressResolver>::Error>>
async fn lookup_ipv4_rand( &self, domain: Domain, ) -> Option<Result<Ipv4Addr, <DomainTrie<R> as DnsAddressResolver>::Error>>
§fn lookup_ipv6(
&self,
domain: Domain,
) -> impl Stream<Item = Result<Ipv6Addr, <DomainTrie<R> as DnsAddressResolver>::Error>> + Send
fn lookup_ipv6( &self, domain: Domain, ) -> impl Stream<Item = Result<Ipv6Addr, <DomainTrie<R> as DnsAddressResolver>::Error>> + Send
§async fn lookup_ipv6_first(
&self,
domain: Domain,
) -> Option<Result<Ipv6Addr, <DomainTrie<R> as DnsAddressResolver>::Error>>
async fn lookup_ipv6_first( &self, domain: Domain, ) -> Option<Result<Ipv6Addr, <DomainTrie<R> as DnsAddressResolver>::Error>>
§async fn lookup_ipv6_rand(
&self,
domain: Domain,
) -> Option<Result<Ipv6Addr, <DomainTrie<R> as DnsAddressResolver>::Error>>
async fn lookup_ipv6_rand( &self, domain: Domain, ) -> Option<Result<Ipv6Addr, <DomainTrie<R> as DnsAddressResolver>::Error>>
§fn into_box_dns_address_resolver(self) -> BoxDnsAddressResolver
fn into_box_dns_address_resolver(self) -> BoxDnsAddressResolver
§impl<R> DnsTxtResolver for DomainTrie<R>where
R: DnsTxtResolver,
impl<R> DnsTxtResolver for DomainTrie<R>where
R: DnsTxtResolver,
§type Error = <R as DnsTxtResolver>::Error
type Error = <R as DnsTxtResolver>::Error
DnsTxtResolver§fn lookup_txt(
&self,
domain: Domain,
) -> impl Stream<Item = Result<Bytes, <DomainTrie<R> as DnsTxtResolver>::Error>> + Send
fn lookup_txt( &self, domain: Domain, ) -> impl Stream<Item = Result<Bytes, <DomainTrie<R> as DnsTxtResolver>::Error>> + Send
§fn into_box_dns_txt_resolver(self) -> BoxDnsTxtResolver
fn into_box_dns_txt_resolver(self) -> BoxDnsTxtResolver
§impl<S, T> FromIterator<(S, T)> for DomainTrie<T>where
S: AsDomainRef,
impl<S, T> FromIterator<(S, T)> for DomainTrie<T>where
S: AsDomainRef,
§fn from_iter<I>(iter: I) -> DomainTrie<T>where
I: IntoIterator<Item = (S, T)>,
fn from_iter<I>(iter: I) -> DomainTrie<T>where
I: IntoIterator<Item = (S, T)>,
Auto Trait Implementations§
impl<T> Freeze for DomainTrie<T>
impl<T> RefUnwindSafe for DomainTrie<T>where
T: RefUnwindSafe,
impl<T> Send for DomainTrie<T>where
T: Send,
impl<T> Sync for DomainTrie<T>where
T: Sync,
impl<T> Unpin for DomainTrie<T>
impl<T> UnsafeUnpin for DomainTrie<T>
impl<T> UnwindSafe for DomainTrie<T>where
T: UnwindSafe,
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<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<R> HappyEyeballAddressResolverExt for Rwhere
R: DnsAddressResolver,
impl<R> HappyEyeballAddressResolverExt for Rwhere
R: DnsAddressResolver,
§fn happy_eyeballs_resolver(
&self,
host: impl Into<Host>,
) -> HappyEyeballAddressResolver<'_, R>
fn happy_eyeballs_resolver( &self, host: impl Into<Host>, ) -> HappyEyeballAddressResolver<'_, R>
§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<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