mirror of https://github.com/rwf2/Rocket.git
Prefer using 'io::Result' responder in docs.
This commit is contained in:
parent
57f27730e7
commit
ab13d73b30
|
@ -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)
|
||||
/// }
|
||||
|
|
|
@ -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))??;
|
||||
|
|
Loading…
Reference in New Issue