~kf5jwc/dns-server-rs

c0b118acfdf52359c048c0ea22681262c5ca611b — Kyle Jones 6 months ago 6533169
Add impl for FromStr trait to QueryType
1 files changed, 17 insertions(+), 0 deletions(-)

M src/dns_packet/query_type.rs
M src/dns_packet/query_type.rs => src/dns_packet/query_type.rs +17 -0
@@ 1,3 1,5 @@
use std::str::FromStr;

#[derive(PartialEq,Eq,Debug,Clone,Hash,Copy)]
pub enum QueryType {
    UNKNOWN(u16),


@@ 48,3 50,18 @@ impl From<u16> for QueryType {
        }
    }
}

impl FromStr for QueryType {
    type Err = &'static str;

    fn from_str(string: &str) -> Result<Self, Self::Err> {
        match string {
            "A" => Ok(Self::A),
            "NS" => Ok(Self::NS),
            "AAAA" => Ok(Self::AAAA),
            "CNAME" => Ok(Self::CNAME),
            "MX" => Ok(Self::MX),
            _ => Err("Unsupported record type!"),
        }
    }
}