Skip to content

Commit

Permalink
Remove domain APIs from edge-captive public API
Browse files Browse the repository at this point in the history
  • Loading branch information
ivmarkov committed Jan 5, 2024
1 parent 0a8ba39 commit b13e0a5
Showing 1 changed file with 20 additions and 27 deletions.
47 changes: 20 additions & 27 deletions edge-captive/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![cfg_attr(not(feature = "std"), no_std)]

use core::fmt;
use core::fmt::{self, Display};
use core::time::Duration;

use log::debug;
Expand All @@ -20,55 +20,48 @@ use domain::{

pub mod io;

#[derive(Debug)]
pub struct InnerError<T: fmt::Debug + fmt::Display>(T);

#[derive(Debug)]
pub enum DnsError {
ShortBuf(InnerError<ShortBuf>),
ShortMessage(InnerError<ShortMessage>),
ParseError(InnerError<ParseError>),
PushError(InnerError<PushError>),
ShortBuf,
InvalidMessage,
}

impl fmt::Display for DnsError {
impl Display for DnsError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
DnsError::ShortBuf(e) => e.0.fmt(f),
DnsError::ShortMessage(e) => e.0.fmt(f),
DnsError::ParseError(e) => e.0.fmt(f),
DnsError::PushError(e) => e.0.fmt(f),
Self::ShortBuf => write!(f, "ShortBuf"),
Self::InvalidMessage => write!(f, "InvalidMessage"),
}
}
}

#[cfg(feature = "std")]
impl std::error::Error for DnsError {}

impl From<ShortBuf> for DnsError {
fn from(e: ShortBuf) -> Self {
Self::ShortBuf(InnerError(e))
fn from(_: ShortBuf) -> Self {
Self::ShortBuf
}
}

impl From<ShortMessage> for DnsError {
fn from(e: ShortMessage) -> Self {
Self::ShortMessage(InnerError(e))
impl From<PushError> for DnsError {
fn from(_: PushError) -> Self {
Self::ShortBuf
}
}

impl From<ParseError> for DnsError {
fn from(e: ParseError) -> Self {
Self::ParseError(InnerError(e))
impl From<ShortMessage> for DnsError {
fn from(_: ShortMessage) -> Self {
Self::InvalidMessage
}
}

impl From<PushError> for DnsError {
fn from(e: PushError) -> Self {
Self::PushError(InnerError(e))
impl From<ParseError> for DnsError {
fn from(_: ParseError) -> Self {
Self::InvalidMessage
}
}

#[cfg(feature = "std")]
impl std::error::Error for DnsError {}

pub fn process_dns_request(
request: &[u8],
ip: &[u8; 4],
Expand Down

0 comments on commit b13e0a5

Please sign in to comment.