Skip to content

Commit

Permalink
More RustDocs.
Browse files Browse the repository at this point in the history
  • Loading branch information
ximon18 committed Mar 30, 2024
1 parent 0cf159c commit cae47b9
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/zonetree/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ pub struct ZoneTree {
}

impl ZoneTree {
/// Creates an empty [`ZoneTree`].
pub fn new() -> Self {
Default::default()
}

/// Gets a [`Zone`] for the given apex name and CLASS, if any.
pub fn get_zone(
&self,
apex_name: &impl ToDname,
Expand All @@ -34,6 +36,10 @@ impl ZoneTree {
.get_zone(apex_name.iter_labels().rev())
}

/// Inserts the given [`Zone`].
///
/// Returns a [`ZoneTreeModificationError`] if a zone with the same apex
/// and CLASS already exists in the tree.
pub fn insert_zone(
&mut self,
zone: Zone,
Expand All @@ -44,6 +50,8 @@ impl ZoneTree {
)
}

/// Gets the closest matching [`Zone`] for the given QNAME and CLASS, if
/// any.
pub fn find_zone(
&self,
qname: &impl ToDname,
Expand All @@ -52,10 +60,12 @@ impl ZoneTree {
self.roots.get(class)?.find_zone(qname.iter_labels().rev())
}

/// Returns an iterator over all of the [`Zone`]s in the tree.
pub fn iter_zones(&self) -> ZoneSetIter {
ZoneSetIter::new(self)
}

/// Removes the specified [`Zone`], if any.
pub fn remove_zone(
&mut self,
apex_name: &impl ToDname,
Expand Down
13 changes: 13 additions & 0 deletions src/zonetree/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,44 @@ use std::vec::Vec;

//------------ Type Aliases --------------------------------------------------

/// A [`Bytes`] backed [`Dname`].
pub type StoredDname = Dname<Bytes>;

/// A [`Bytes`] backed [`ZoneRecordData`].
pub type StoredRecordData = ZoneRecordData<Bytes, StoredDname>;

/// A [`Bytes`] backed [`Record`].`
pub type StoredRecord = Record<StoredDname, StoredRecordData>;

//------------ SharedRr ------------------------------------------------------

/// A cheaply clonable resource record.
///
/// A [`Bytes`] backed resource record which is cheap to [`Clone`] because
/// [`Bytes`] is cheap to clone.
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct SharedRr {
ttl: Ttl,
data: StoredRecordData,
}

impl SharedRr {
/// Create a new [`SharedRr`] instance.
pub fn new(ttl: Ttl, data: StoredRecordData) -> Self {
SharedRr { ttl, data }
}

/// Gets the type of this resource record.
pub fn rtype(&self) -> Rtype {
self.data.rtype()
}

/// Gets the TTL of this resource record.
pub fn ttl(&self) -> Ttl {
self.ttl
}

/// Gets a reference to the data of this resource record.
pub fn data(&self) -> &StoredRecordData {
&self.data
}
Expand Down
2 changes: 2 additions & 0 deletions src/zonetree/walk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ use super::Rrset;
use crate::base::name::OwnedLabel;
use crate::base::{Dname, DnameBuilder};

/// A callback function invoked for each leaf node visited while walking a
/// [`Zone`].
pub type WalkOp = Box<dyn Fn(Dname<Bytes>, &Rrset) + Send + Sync>;

struct WalkStateInner {
Expand Down
7 changes: 6 additions & 1 deletion src/zonetree/zone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,38 @@ use super::in_memory::ZoneBuilder;
use super::traits::WritableZone;
use super::{ReadableZone, StoredDname, ZoneStore};

// TODO: Delete Zone, rename ZoneStore to Zone (and make ZoneSetNode generic?)
//------------ Zone ----------------------------------------------------------

/// A single DNS zone.
#[derive(Debug)]
pub struct Zone {
store: Arc<dyn ZoneStore>,
}

impl Zone {
/// Creates a new [`Zone`] instance with the given data.
pub fn new(data: impl ZoneStore + 'static) -> Self {
Zone {
store: Arc::new(data),
}
}

/// Gets the CLASS of this zone.
pub fn class(&self) -> Class {
self.store.class()
}

/// Gets the apex name of this zone.
pub fn apex_name(&self) -> &StoredDname {
self.store.apex_name()
}

/// Gets a read interface to this zone.
pub fn read(&self) -> Box<dyn ReadableZone> {
self.store.clone().read()
}

/// Gets a write interface to this zone.
pub fn write(
&self,
) -> Pin<Box<dyn Future<Output = Box<dyn WritableZone>>>> {
Expand Down

0 comments on commit cae47b9

Please sign in to comment.