Prefer using 'io::Result' responder in docs.

This commit is contained in:
Sergio Benitez 2021-05-22 22:12:46 -07:00
parent 57f27730e7
commit ab13d73b30
2 changed files with 3 additions and 4 deletions

View File

@ -94,10 +94,9 @@ use crate::http::uncased::Uncased;
/// use std::io;
///
/// use rocket::data::{Data, Limits, ToByteUnit};
/// use rocket::response::Debug;
///
/// #[post("/echo", data = "<data>")]
/// async fn echo(data: Data, limits: &Limits) -> Result<String, Debug<io::Error>> {
/// async fn echo(data: Data, limits: &Limits) -> io::Result<String> {
/// let limit = limits.get("data").unwrap_or(1.mebibytes());
/// Ok(data.open(limit).into_string().await?.value)
/// }

View File

@ -298,11 +298,11 @@ necessary, you can convert a synchronous operation to an async one with
```rust
# #[macro_use] extern crate rocket;
use std::io;
use rocket::tokio::task::spawn_blocking;
use rocket::response::Debug;
#[get("/blocking_task")]
async fn blocking_task() -> Result<Vec<u8>, Debug<io::Error>> {
async fn blocking_task() -> io::Result<Vec<u8>> {
// In a real app, use rocket::fs::NamedFile or tokio::fs::File.
let vec = spawn_blocking(|| std::fs::read("data.txt")).await
.map_err(|e| io::Error::new(io::ErrorKind::Interrupted, e))??;