@@ -25,6 +25,7 @@ pub struct Response {
2525
2626impl Response {
2727 /// Create a new instance.
28+ #[ must_use]
2829 pub fn new ( status : StatusCode ) -> Self {
2930 let res = http_types:: Response :: new ( status) ;
3031 Self {
@@ -72,22 +73,32 @@ impl Response {
7273 }
7374
7475 /// Returns the statuscode.
76+ #[ must_use]
7577 pub fn status ( & self ) -> crate :: StatusCode {
7678 self . res . status ( )
7779 }
7880
7981 /// Set the statuscode.
82+ #[ must_use]
8083 pub fn set_status ( mut self , status : crate :: StatusCode ) -> Self {
8184 self . res . set_status ( status) ;
8285 self
8386 }
8487
8588 /// Get the length of the body.
89+ #[ must_use]
8690 pub fn len ( & self ) -> Option < usize > {
8791 self . res . len ( )
8892 }
8993
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+
90100 /// Get an HTTP header.
101+ #[ must_use]
91102 pub fn header ( & self , name : & HeaderName ) -> Option < & Vec < HeaderValue > > {
92103 self . res . header ( name)
93104 }
@@ -126,6 +137,7 @@ impl Response {
126137 /// Set the request MIME.
127138 ///
128139 /// [Read more on MDN](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types)
140+ #[ must_use]
129141 pub fn set_mime ( self , mime : Mime ) -> Self {
130142 self . set_header ( http_types:: headers:: CONTENT_TYPE , format ! ( "{}" , mime) )
131143 }
@@ -135,6 +147,7 @@ impl Response {
135147 /// # Mime
136148 ///
137149 /// The encoding is set to `text/plain; charset=utf-8`.
150+ #[ must_use]
138151 pub fn body_string ( mut self , string : String ) -> Self {
139152 self . res . set_body ( string) ;
140153 self . set_mime ( mime:: TEXT_PLAIN_UTF_8 )
@@ -167,7 +180,7 @@ impl Response {
167180 pub async fn body_form < T : serde:: Serialize > (
168181 mut self ,
169182 form : T ,
170- ) -> Result < Response , serde_qs:: Error > {
183+ ) -> Result < Self , serde_qs:: Error > {
171184 // TODO: think about how to handle errors
172185 self . res . set_body ( serde_qs:: to_string ( & form) ?. into_bytes ( ) ) ;
173186 Ok ( self
@@ -221,6 +234,7 @@ impl Response {
221234 }
222235
223236 /// Get a local value.
237+ #[ must_use]
224238 pub fn local < T : Send + Sync + ' static > ( & self ) -> Option < & T > {
225239 self . res . local ( ) . get ( )
226240 }
0 commit comments