@@ -4,7 +4,6 @@ use super::resource::*;
4
4
use super :: * ;
5
5
use crate :: error:: * ;
6
6
7
- use anyhow:: Result ;
8
7
use std:: collections:: HashMap ;
9
8
10
9
// A Builder allows incrementally packing a DNS message.
@@ -84,10 +83,10 @@ impl Builder {
84
83
85
84
fn start_check ( & self , section : Section ) -> Result < ( ) > {
86
85
if self . section <= Section :: NotStarted {
87
- return Err ( Error :: ErrNotStarted . into ( ) ) ;
86
+ return Err ( Error :: ErrNotStarted ) ;
88
87
}
89
88
if self . section > section {
90
- return Err ( Error :: ErrSectionDone . into ( ) ) ;
89
+ return Err ( Error :: ErrSectionDone ) ;
91
90
}
92
91
93
92
Ok ( ( ) )
@@ -128,13 +127,13 @@ impl Builder {
128
127
Section :: Answers => ( & mut self . header . answers , Error :: ErrTooManyAnswers ) ,
129
128
Section :: Authorities => ( & mut self . header . authorities , Error :: ErrTooManyAuthorities ) ,
130
129
Section :: Additionals => ( & mut self . header . additionals , Error :: ErrTooManyAdditionals ) ,
131
- Section :: NotStarted => return Err ( Error :: ErrNotStarted . into ( ) ) ,
132
- Section :: Done => return Err ( Error :: ErrSectionDone . into ( ) ) ,
133
- Section :: Header => return Err ( Error :: ErrSectionHeader . into ( ) ) ,
130
+ Section :: NotStarted => return Err ( Error :: ErrNotStarted ) ,
131
+ Section :: Done => return Err ( Error :: ErrSectionDone ) ,
132
+ Section :: Header => return Err ( Error :: ErrSectionHeader ) ,
134
133
} ;
135
134
136
135
if * count == u16:: MAX {
137
- Err ( err. into ( ) )
136
+ Err ( err)
138
137
} else {
139
138
* count += 1 ;
140
139
Ok ( ( ) )
@@ -144,10 +143,10 @@ impl Builder {
144
143
// question adds a single question.
145
144
pub fn add_question ( & mut self , q : & Question ) -> Result < ( ) > {
146
145
if self . section < Section :: Questions {
147
- return Err ( Error :: ErrNotStarted . into ( ) ) ;
146
+ return Err ( Error :: ErrNotStarted ) ;
148
147
}
149
148
if self . section > Section :: Questions {
150
- return Err ( Error :: ErrSectionDone . into ( ) ) ;
149
+ return Err ( Error :: ErrSectionDone ) ;
151
150
}
152
151
let msg = self . msg . take ( ) ;
153
152
if let Some ( mut msg) = msg {
@@ -161,10 +160,10 @@ impl Builder {
161
160
162
161
fn check_resource_section ( & self ) -> Result < ( ) > {
163
162
if self . section < Section :: Answers {
164
- return Err ( Error :: ErrNotStarted . into ( ) ) ;
163
+ return Err ( Error :: ErrNotStarted ) ;
165
164
}
166
165
if self . section > Section :: Additionals {
167
- return Err ( Error :: ErrSectionDone . into ( ) ) ;
166
+ return Err ( Error :: ErrSectionDone ) ;
168
167
}
169
168
Ok ( ( ) )
170
169
}
@@ -176,7 +175,7 @@ impl Builder {
176
175
if let Some ( body) = & r. body {
177
176
r. header . typ = body. real_type ( ) ;
178
177
} else {
179
- return Err ( Error :: ErrNilResourceBody . into ( ) ) ;
178
+ return Err ( Error :: ErrNilResourceBody ) ;
180
179
}
181
180
182
181
if let Some ( msg) = self . msg . take ( ) {
@@ -196,7 +195,7 @@ impl Builder {
196
195
// Finish ends message building and generates a binary message.
197
196
pub fn finish ( & mut self ) -> Result < Vec < u8 > > {
198
197
if self . section < Section :: Header {
199
- return Err ( Error :: ErrNotStarted . into ( ) ) ;
198
+ return Err ( Error :: ErrNotStarted ) ;
200
199
}
201
200
self . section = Section :: Done ;
202
201
@@ -207,7 +206,7 @@ impl Builder {
207
206
msg[ ..HEADER_LEN ] . copy_from_slice ( & buf[ ..HEADER_LEN ] ) ;
208
207
Ok ( msg)
209
208
} else {
210
- Err ( Error :: ErrEmptyBuilderMsg . into ( ) )
209
+ Err ( Error :: ErrEmptyBuilderMsg )
211
210
}
212
211
}
213
212
}
0 commit comments