dns_types::zones::types

Struct Zone

Source
pub struct Zone {
    apex: DomainName,
    soa: Option<SOA>,
    records: ZoneRecords,
}
Expand description

A zone is a collection of records all belonging to the same domain name.

Fields§

§apex: DomainName

The domain name which the records all belong to.

§soa: Option<SOA>

The SOA record for this zone, if it is authoritative.

§records: ZoneRecords

Records. These are indexed by label, with the labels relative to the apex. For example, if the apex is “barrucadu.co.uk”, then records for “www.barrucadu.co.uk” would be indexed under “www”.

Implementations§

Source§

impl Zone

Source

pub fn deserialise(data: &str) -> Result<Self, Error>

Parse a string of zone data

This implementation does not support $INCLUDE entries or non-IN record classes. These will raise an error.

§Errors

If the string cannot be parsed.

Source§

impl Zone

Source

pub fn serialise(&self) -> String

Source

fn serialise_domain(&self, name: &DomainName) -> String

Serialise a domain name: dotted string format, with the apex chopped off if this is an authoritative zone (unless the apex is the root domain, because that’s only a single character long so we may as well show it).

Source

pub fn serialise_rdata(&self, rtype_with_data: &RecordTypeWithData) -> String

Serialise the RDATA, with domains displayed relative to the apex (if authoritative).

Source§

impl Zone

Source

pub fn new(apex: DomainName, soa: Option<SOA>) -> Self

Construct a new zone.

If there is a SOA value, it is inserted as an RR at the root of the zone.

Source

pub fn get_apex(&self) -> &DomainName

Returns the apex domain.

Source

pub fn get_soa(&self) -> Option<&SOA>

Return the SOA if the zone is authoritative.

Source

pub fn is_authoritative(&self) -> bool

Returns true if the zone is authoritative.

Source

pub fn soa_rr(&self) -> Option<ResourceRecord>

Returns the SOA RR if the zone is authoritative.

Source

pub fn resolve(&self, name: &DomainName, qtype: QueryType) -> Option<ZoneResult>

Resolve a query. Returns None if the domain is not a subdomain of the apex.

This corresponds to step 3 of the standard nameserver algorithm (see section 4.3.2 of RFC 1034).

Source

pub fn insert( &mut self, name: &DomainName, rtype_with_data: RecordTypeWithData, ttl: u32, )

Insert a record for a domain. This domain MUST be a subdomain of the apex.

Note that, for authoritative zones, the SOA minimum field is a lower bound on the TTL of any RR in the zone. So if this TTL is lower, it will be raised.

Source

pub fn insert_wildcard( &mut self, name: &DomainName, rtype_with_data: RecordTypeWithData, ttl: u32, )

Insert a wildcard record for a domain. This domain MUST be a subdomain of the apex.

Note that, for authoritative zones, the SOA minimum field is a lower bound on the TTL of any RR in the zone. So if this TTL is lower, it will be raised.

Source

pub fn relative_domain<'a>(&self, name: &'a DomainName) -> Option<&'a [Label]>

Take a domain and chop off the suffix corresponding to the apex of this zone.

Returns None if the given domain does not match the apex.

Source

pub fn actual_ttl(&self, ttl: u32) -> u32

If this zone is authoritative, and the given TTL is below the SOA minimum field, returns the SOA minimum field.

Otherwise returns the given TTL.

Source

pub fn merge(&mut self, other: Zone) -> Result<(), (DomainName, DomainName)>

Merge another zone into this one.

§Errors

If the apex does not match.

Source

pub fn all_records(&self) -> HashMap<&DomainName, Vec<&ZoneRecord>>

Return all the records in the zone.

Source

pub fn all_wildcard_records(&self) -> HashMap<&DomainName, Vec<&ZoneRecord>>

Return all the wildcard records in the zone.

Trait Implementations§

Source§

impl Clone for Zone

Source§

fn clone(&self) -> Zone

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Zone

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Zone

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl From<Hosts> for Zone

Source§

fn from(hosts: Hosts) -> Zone

Converts to this type from the input type.
Source§

impl PartialEq for Zone

Source§

fn eq(&self, other: &Zone) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl TryFrom<Zone> for Hosts

Source§

fn try_from(zone: Zone) -> Result<Self, Self::Error>

§Errors

If the zone has wildcard domain names or non-A / non-AAAA record types.

Source§

type Error = TryFromZoneError

The type returned in the event of a conversion error.
Source§

impl Eq for Zone

Source§

impl StructuralPartialEq for Zone

Auto Trait Implementations§

§

impl Freeze for Zone

§

impl RefUnwindSafe for Zone

§

impl Send for Zone

§

impl Sync for Zone

§

impl Unpin for Zone

§

impl UnwindSafe for Zone

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.