use std::boxed::Box;
use bytes::Bytes;
use tokio::sync::mpsc::UnboundedSender;
use tracing::error;
use crate::base::{Name, Rtype};
use crate::net::server::service::{CallResult, ServiceResult};
use crate::zonetree::error::OutOfZone;
use crate::zonetree::{Answer, ReadableZone};
#[allow(clippy::borrowed_box)]
pub async fn read_soa(
read: &Box<dyn ReadableZone>,
qname: Name<Bytes>,
) -> Result<Answer, OutOfZone> {
match read.is_async() {
true => read.query_async(qname, Rtype::SOA).await,
false => read.query(qname, Rtype::SOA),
}
}
pub fn add_to_stream<Target, T: Into<CallResult<Target>>>(
call_result: T,
response_tx: &UnboundedSender<ServiceResult<Target>>,
) {
if response_tx.send(Ok(call_result.into())).is_err() {
error!("Failed to send DNS message to the internal response stream");
}
}