@@ -302,30 +302,30 @@ impl<State: Send + Sync + 'static> Server<State> {
302
302
/// # #[async_std::main]
303
303
/// # async fn main() -> http_types::Result<()> {
304
304
/// #
305
- /// use tide::http::{self, Url, Method};
305
+ /// use tide::http::{Url, Method, Request, Response };
306
306
///
307
307
/// // Initialize the application with state.
308
308
/// let mut app = tide::new();
309
309
/// app.at("/").get(|_| async move { Ok("hello world") });
310
310
///
311
- /// let req = http:: Request::new(Method::Get, Url::parse("https://example.com")?);
312
- /// let res = app.respond(req).await?;
311
+ /// let req = Request::new(Method::Get, Url::parse("https://example.com")?);
312
+ /// let res: Response = app.respond(req).await?;
313
313
/// assert_eq!(res.status(), 200);
314
314
/// #
315
315
/// # Ok(()) }
316
316
/// ```
317
- pub async fn respond (
318
- & self ,
319
- req : impl Into < http_types:: Request > ,
320
- ) -> http_types :: Result < http_types :: Response > {
317
+ pub async fn respond < R > ( & self , req : impl Into < http_types :: Request > ) -> http_types :: Result < R >
318
+ where
319
+ R : From < http_types:: Response > ,
320
+ {
321
321
let req = Request :: new ( self . state . clone ( ) , req. into ( ) , Vec :: new ( ) ) ;
322
322
match self . call ( req) . await {
323
323
Ok ( value) => {
324
- let res = value. into ( ) ;
324
+ let res: http_types :: Response = value. into ( ) ;
325
325
// We assume that if an error was manually cast to a
326
326
// Response that we actually want to send the body to the
327
327
// client. At this point we don't scrub the message.
328
- Ok ( res)
328
+ Ok ( res. into ( ) )
329
329
}
330
330
Err ( err) => {
331
331
let mut res = http_types:: Response :: new ( err. status ( ) ) ;
@@ -336,7 +336,7 @@ impl<State: Send + Sync + 'static> Server<State> {
336
336
if !res. status ( ) . is_server_error ( ) {
337
337
res. set_body ( err. to_string ( ) ) ;
338
338
}
339
- Ok ( res)
339
+ Ok ( res. into ( ) )
340
340
}
341
341
}
342
342
}
0 commit comments