@@ -25,6 +25,7 @@ pub struct Response {
25
25
26
26
impl Response {
27
27
/// Create a new instance.
28
+ #[ must_use]
28
29
pub fn new ( status : StatusCode ) -> Self {
29
30
let res = http_types:: Response :: new ( status) ;
30
31
Self {
@@ -72,22 +73,32 @@ impl Response {
72
73
}
73
74
74
75
/// Returns the statuscode.
76
+ #[ must_use]
75
77
pub fn status ( & self ) -> crate :: StatusCode {
76
78
self . res . status ( )
77
79
}
78
80
79
81
/// Set the statuscode.
82
+ #[ must_use]
80
83
pub fn set_status ( mut self , status : crate :: StatusCode ) -> Self {
81
84
self . res . set_status ( status) ;
82
85
self
83
86
}
84
87
85
88
/// Get the length of the body.
89
+ #[ must_use]
86
90
pub fn len ( & self ) -> Option < usize > {
87
91
self . res . len ( )
88
92
}
89
93
94
+ /// Checks if the body is empty.
95
+ #[ must_use]
96
+ pub fn is_empty ( & self ) -> Option < bool > {
97
+ Some ( self . res . len ( ) ? == 0 )
98
+ }
99
+
90
100
/// Get an HTTP header.
101
+ #[ must_use]
91
102
pub fn header ( & self , name : & HeaderName ) -> Option < & Vec < HeaderValue > > {
92
103
self . res . header ( name)
93
104
}
@@ -126,6 +137,7 @@ impl Response {
126
137
/// Set the request MIME.
127
138
///
128
139
/// [Read more on MDN](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types)
140
+ #[ must_use]
129
141
pub fn set_mime ( self , mime : Mime ) -> Self {
130
142
self . set_header ( http_types:: headers:: CONTENT_TYPE , format ! ( "{}" , mime) )
131
143
}
@@ -135,6 +147,7 @@ impl Response {
135
147
/// # Mime
136
148
///
137
149
/// The encoding is set to `text/plain; charset=utf-8`.
150
+ #[ must_use]
138
151
pub fn body_string ( mut self , string : String ) -> Self {
139
152
self . res . set_body ( string) ;
140
153
self . set_mime ( mime:: TEXT_PLAIN_UTF_8 )
@@ -167,7 +180,7 @@ impl Response {
167
180
pub async fn body_form < T : serde:: Serialize > (
168
181
mut self ,
169
182
form : T ,
170
- ) -> Result < Response , serde_qs:: Error > {
183
+ ) -> Result < Self , serde_qs:: Error > {
171
184
// TODO: think about how to handle errors
172
185
self . res . set_body ( serde_qs:: to_string ( & form) ?. into_bytes ( ) ) ;
173
186
Ok ( self
@@ -221,6 +234,7 @@ impl Response {
221
234
}
222
235
223
236
/// Get a local value.
237
+ #[ must_use]
224
238
pub fn local < T : Send + Sync + ' static > ( & self ) -> Option < & T > {
225
239
self . res . local ( ) . get ( )
226
240
}
0 commit comments