1
- #![ cfg_attr( not( test) , no_std) ]
1
+ #![ cfg_attr( all ( feature = "no_std" , not( test) ) , no_std) ]
2
2
#![ cfg_attr( test, deny( warnings) ) ]
3
3
#![ deny( missing_docs) ]
4
4
//! # httparse
16
16
17
17
#[ cfg( test) ] extern crate core;
18
18
19
- use core:: { str, slice} ;
19
+ #[ cfg( feature = "no_std" ) ]
20
+ use core:: { fmt, result, str, slice} ;
21
+
22
+ #[ cfg( not( feature = "no_std" ) ) ]
23
+ use std:: { fmt, result, str, slice} ;
24
+
20
25
use iter:: Bytes ;
21
26
22
27
mod iter;
@@ -111,27 +116,41 @@ pub enum Error {
111
116
Version ,
112
117
}
113
118
114
- impl :: core:: fmt:: Display for Error {
115
- fn fmt ( & self , f : & mut :: core:: fmt:: Formatter ) -> :: core:: fmt:: Result {
119
+ impl Error {
120
+ #[ inline]
121
+ fn description_str ( & self ) -> & ' static str {
116
122
match * self {
117
- Error :: HeaderName => f . write_str ( "invalid header name" ) ,
118
- Error :: HeaderValue => f . write_str ( "invalid header value" ) ,
119
- Error :: NewLine => f . write_str ( "invalid new line" ) ,
120
- Error :: Status => f . write_str ( "invalid response status" ) ,
121
- Error :: Token => f . write_str ( "invalid token" ) ,
122
- Error :: TooManyHeaders => f . write_str ( "too many headers" ) ,
123
- Error :: Version => f . write_str ( "invalid HTTP version" ) ,
123
+ Error :: HeaderName => "invalid header name" ,
124
+ Error :: HeaderValue => "invalid header value" ,
125
+ Error :: NewLine => "invalid new line" ,
126
+ Error :: Status => "invalid response status" ,
127
+ Error :: Token => "invalid token" ,
128
+ Error :: TooManyHeaders => "too many headers" ,
129
+ Error :: Version => "invalid HTTP version" ,
124
130
}
125
131
}
126
132
}
127
133
134
+ impl fmt:: Display for Error {
135
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
136
+ f. write_str ( self . description_str ( ) )
137
+ }
138
+ }
139
+
140
+ #[ cfg( not( feature = "no_std" ) ) ]
141
+ impl std:: error:: Error for Error {
142
+ fn description ( & self ) -> & str {
143
+ self . description_str ( )
144
+ }
145
+ }
146
+
128
147
/// An error in parsing a chunk size.
129
148
// Note: Move this into the error enum once v2.0 is released.
130
149
#[ derive( Debug , PartialEq , Eq ) ]
131
150
pub struct InvalidChunkSize ;
132
151
133
- impl :: core :: fmt:: Display for InvalidChunkSize {
134
- fn fmt ( & self , f : & mut :: core :: fmt:: Formatter ) -> :: core :: fmt:: Result {
152
+ impl fmt:: Display for InvalidChunkSize {
153
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
135
154
f. write_str ( "invalid chunk size" )
136
155
}
137
156
}
@@ -141,7 +160,7 @@ impl ::core::fmt::Display for InvalidChunkSize {
141
160
/// If the input is invalid, an `Error` will be returned. Note that incomplete
142
161
/// data is not considered invalid, and so will not return an error, but rather
143
162
/// a `Ok(Status::Partial)`.
144
- pub type Result < T > = :: core :: result:: Result < Status < T > , Error > ;
163
+ pub type Result < T > = result:: Result < Status < T > , Error > ;
145
164
146
165
/// The result of a successful parse pass.
147
166
///
@@ -581,7 +600,7 @@ fn parse_headers_iter<'a, 'b>(headers: &mut &mut [Header<'a>], bytes: &'b mut By
581
600
/// Ok(httparse::Status::Complete((3, 4))));
582
601
/// ```
583
602
pub fn parse_chunk_size ( buf : & [ u8 ] )
584
- -> :: core :: result:: Result < Status < ( usize , u64 ) > , InvalidChunkSize > {
603
+ -> result:: Result < Status < ( usize , u64 ) > , InvalidChunkSize > {
585
604
const RADIX : u64 = 16 ;
586
605
let mut bytes = Bytes :: new ( buf) ;
587
606
let mut size = 0 ;
0 commit comments