1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
use crate::{Class, DomainName, Type};

use std::fmt::{Display, Formatter, Result as FmtResult};

#[derive(Debug, Clone, FromPrimitive, ToPrimitive, PartialEq, Eq, Hash)]
pub enum QType_ {
    AXFR = 252,
    MAILB = 253,
    MAILA = 254,
    ALL = 255,
}

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum QType {
    Type(Type),
    QType(QType_),
}

impl Display for QType {
    fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
        match self {
            QType::Type(t) => write!(f, "{:?}", t),
            QType::QType(t) => write!(f, "{:?}", t),
        }
    }
}

#[derive(Debug, Clone, FromPrimitive, ToPrimitive, PartialEq, Eq, Hash)]
pub enum QClass_ {
    ANY = 255,
}

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum QClass {
    Class(Class),
    QClass(QClass_),
}

impl Display for QClass {
    fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
        match self {
            QClass::Class(c) => write!(f, "{:?}", c),
            QClass::QClass(c) => write!(f, "{:?}", c),
        }
    }
}

#[derive(Debug, Getters, Clone, PartialEq, Eq, Hash)]
pub struct Question {
    #[get = "pub with_prefix"]
    pub(crate) domain_name: DomainName,
    #[get = "pub with_prefix"]
    pub(crate) qtype: QType,
    #[get = "pub with_prefix"]
    pub(crate) qclass: QClass,
}

impl Question {
    pub fn new(domain_name: DomainName, qclass: QClass, qtype: QType) -> Question {
        Question {
            domain_name,
            qclass,
            qtype,
        }
    }
}

impl Display for Question {
    fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
        write!(f, "{} {} {}", self.domain_name, self.qclass, self.qtype)
    }
}