file
ModuleZone files (RFC 1035 §5, the master file format).
Contents
use utopia_dns::zone::file::export;pub fn export(zone: &Zone, include_comments: bool) -> Vec<u8>Exports a zone as a zone file: $ORIGIN, $TTL (the SOA's), the
SOA over several lines, then the records grouped by type (NS, A,
AAAA, MX, CNAME, TXT, then the others in order of appearance),
with names relative to the zone. Comments, when included, head the file
(with the time, from std::time::SystemTime, in UTC) and each group.
use utopia_dns::zone::file::export_at;pub fn export_at(zone: &Zone, include_comments: bool, generated: &str) -> Vec<u8>export with the time written in the header comment (Y-m-d H:i:s).
use utopia_dns::zone::file::import;pub fn import(content: &[u8], default_origin: Option<&[u8]>, default_ttl: i64) -> Result<Zone, Error>Imports a zone from a zone file.
Supports $ORIGIN and $TTL (other $ directives are skipped,
$INCLUDE is refused), @, relative names, omitted owners (the
previous one), omitted TTLs and classes (the previous ones, in any
order), ; comments outside quotes, and records spanning lines in
parentheses. TXT strings are joined and \DDD escapes decoded. The zone
is named by the first $ORIGIN, else default_origin; it needs exactly
one SOA record.
Fails with Error::Import, carrying the file.
use utopia_dns::zone;
let zone = zone::import(b"$ORIGIN example.com.
$TTL 1800
@ IN SOA ns1.example.com. admin.example.com. 2025011801 7200 3600 1209600 1800
www IN A 192.168.1.10
mail 300 IN MX 10 mail", None, 3600)?;
assert_eq!(zone.name(), b"example.com");
assert_eq!(zone.records()[1].rdata(), b"mail.example.com");
assert_eq!(zone.records()[1].priority(), Some(10));