Skip to content

Remove Ok(()) with .await as end statement #471

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ async-std = { version = "1.5.0", features = ["attributes"] }
async fn main() -> Result<(), std::io::Error> {
let mut app = tide::new();
app.at("/").get(|_| async { Ok("Hello, world!") });
app.listen("127.0.0.1:8080").await?;
Ok(())
app.listen("127.0.0.1:8080").await
}
```

Expand Down
3 changes: 1 addition & 2 deletions examples/chunked.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ fn main() -> Result<(), std::io::Error> {
let res = Response::new(StatusCode::Ok).body(BufReader::new(file));
Ok(res)
});
app.listen("127.0.0.1:8080").await?;
Ok(())
app.listen("127.0.0.1:8080").await
})
}
4 changes: 1 addition & 3 deletions examples/cookies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ fn main() -> Result<(), std::io::Error> {
app.at("/").get(retrieve_cookie);
app.at("/set").get(set_cookie);
app.at("/remove").get(remove_cookie);
app.listen("127.0.0.1:8080").await?;

Ok(())
app.listen("127.0.0.1:8080").await
})
}
4 changes: 2 additions & 2 deletions examples/fib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ async fn fibsum(req: Request<()>) -> tide::Result<String> {
);
Ok(res)
}

// Example: HTTP GET to http://localhost:8080/fib/42
// $ curl "http://localhost:8080/fib/42"
// The fib of 42 is 267914296.
Expand All @@ -33,7 +34,6 @@ fn main() -> Result<(), std::io::Error> {
task::block_on(async {
let mut app = tide::new();
app.at("/fib/:n").get(fibsum);
app.listen("0.0.0.0:8080").await?;
Ok(())
app.listen("0.0.0.0:8080").await
})
}
3 changes: 1 addition & 2 deletions examples/graphql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ fn main() -> std::io::Result<()> {
app.at("/").get(redirect::permanent("/graphiql"));
app.at("/graphql").post(handle_graphql);
app.at("/graphiql").get(handle_graphiql);
app.listen("0.0.0.0:8080").await?;
Ok(())
app.listen("0.0.0.0:8080").await
})
}
3 changes: 1 addition & 2 deletions examples/hello.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ fn main() -> Result<(), std::io::Error> {
task::block_on(async {
let mut app = tide::new();
app.at("/").get(|_| async move { Ok("Hello, world!") });
app.listen("127.0.0.1:8080").await?;
Ok(())
app.listen("127.0.0.1:8080").await
})
}
3 changes: 1 addition & 2 deletions examples/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ fn main() -> io::Result<()> {
Ok(Response::new(StatusCode::Ok).body_json(&cat)?)
});

app.listen("127.0.0.1:8080").await?;
Ok(())
app.listen("127.0.0.1:8080").await
})
}
3 changes: 1 addition & 2 deletions examples/nested.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@ async fn main() -> Result<(), std::io::Error> {
.get(|_| async move { Ok("Goodbye, world") });
api
});
app.listen("127.0.0.1:8080").await?;
Ok(())
app.listen("127.0.0.1:8080").await
}
3 changes: 1 addition & 2 deletions examples/sse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@ async fn main() -> Result<(), std::io::Error> {
sender.send("fruit", "apple", None).await;
Ok(())
}));
app.listen("localhost:8080").await?;
Ok(())
app.listen("localhost:8080").await
}
3 changes: 1 addition & 2 deletions examples/static_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ fn main() -> Result<(), std::io::Error> {
let mut app = tide::new();
app.at("/").get(|_| async move { Ok("visit /src/*") });
app.at("/src").serve_dir("src/")?;
app.listen("127.0.0.1:8080").await?;
Ok(())
app.listen("127.0.0.1:8080").await
})
}
20 changes: 10 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
//! #
//! let mut app = tide::new();
//! app.at("/").get(|_| async move { Ok("Hello, world!") });
//! app.listen("127.0.0.1:8080").await?;
//! app.listen("127.0.0.1:8080").await
//! #
//! # Ok(()) }) }
//! # }) }
//! ```
//!
//! __echo server__
Expand All @@ -42,9 +42,9 @@
//! #
//! let mut app = tide::new();
//! app.at("/").get(|req| async move { Ok(req) });
//! app.listen("127.0.0.1:8080").await?;
//! app.listen("127.0.0.1:8080").await
//! #
//! # Ok(()) }) }
//! # }) }
//! ````
//!
//! __send and receive json__
Expand All @@ -63,9 +63,9 @@
//! counter.count += 1;
//! Ok(Response::new(tide::http::StatusCode::Ok).body_json(&counter)?)
//! });
//! app.listen("127.0.0.1:8080").await?;
//! app.listen("127.0.0.1:8080").await
//! #
//! # Ok(()) }) }
//! # }) }
//! ```
//!
//! # Concepts
Expand Down Expand Up @@ -226,9 +226,9 @@ pub use http_types as http;
/// #
/// let mut app = tide::new();
/// app.at("/").get(|_| async move { Ok("Hello, world!") });
/// app.listen("127.0.0.1:8080").await?;
/// app.listen("127.0.0.1:8080").await
/// #
/// # Ok(()) }) }
/// # }) }
/// ```
pub fn new() -> server::Server<()> {
Server::new()
Expand Down Expand Up @@ -261,9 +261,9 @@ pub fn new() -> server::Server<()> {
/// app.at("/").get(|req: Request<State>| async move {
/// Ok(format!("Hello, {}!", &req.state().name))
/// });
/// app.listen("127.0.0.1:8080").await?;
/// app.listen("127.0.0.1:8080").await
/// #
/// # Ok(()) }) }
/// # }) }
/// ```
pub fn with_state<State>(state: State) -> server::Server<State>
where
Expand Down
4 changes: 2 additions & 2 deletions src/redirect/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
//! let mut app = tide::new();
//! app.at("/").get(|_| async move { Ok("meow") });
//! app.at("/nori").get(redirect::temporary("/"));
//! app.listen("127.0.0.1:8080").await?;
//! app.listen("127.0.0.1:8080").await
//! #
//! # Ok(()) }) }
//! # }) }
//! ```
mod permanent;
mod temporary;
Expand Down
4 changes: 2 additions & 2 deletions src/redirect/permanent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ use crate::{Endpoint, Request, Response};
/// let mut app = tide::new();
/// app.at("/").get(|_| async move { Ok("meow") });
/// app.at("/nori").get(redirect::permanent("/"));
/// app.listen("127.0.0.1:8080").await?;
/// app.listen("127.0.0.1:8080").await
/// #
/// # Ok(()) }) }
/// # }) }
/// ```
pub fn permanent(location: impl AsRef<str>) -> PermanentRedirect {
let location = location.as_ref().to_owned();
Expand Down
4 changes: 2 additions & 2 deletions src/redirect/temporary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ use crate::{Endpoint, Request, Response};
/// let mut app = tide::new();
/// app.at("/").get(|_| async move { Ok("meow") });
/// app.at("/nori").get(redirect::temporary("/"));
/// app.listen("127.0.0.1:8080").await?;
/// app.listen("127.0.0.1:8080").await
/// #
/// # Ok(()) }) }
/// # }) }
/// ```
pub fn temporary(location: impl AsRef<str>) -> TemporaryRedirect {
let location = location.as_ref().to_owned();
Expand Down
24 changes: 12 additions & 12 deletions src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ impl<State> Request<State> {
/// assert_eq!(req.method(), http_types::Method::Get);
/// Ok("")
/// });
/// app.listen("127.0.0.1:8080").await?;
/// app.listen("127.0.0.1:8080").await
/// #
/// # Ok(()) })}
/// # })}
/// ```
pub fn method(&self) -> Method {
self.request.method()
Expand All @@ -80,9 +80,9 @@ impl<State> Request<State> {
/// assert_eq!(req.uri(), &"/".parse::<tide::http::Url>().unwrap());
/// Ok("")
/// });
/// app.listen("127.0.0.1:8080").await?;
/// app.listen("127.0.0.1:8080").await
/// #
/// # Ok(()) })}
/// # })}
/// ```
pub fn uri(&self) -> &Url {
self.request.url()
Expand All @@ -103,9 +103,9 @@ impl<State> Request<State> {
/// assert_eq!(req.version(), Some(http_types::Version::Http1_1));
/// Ok("")
/// });
/// app.listen("127.0.0.1:8080").await?;
/// app.listen("127.0.0.1:8080").await
/// #
/// # Ok(()) })}
/// # })}
/// ```
pub fn version(&self) -> Option<Version> {
self.request.version()
Expand All @@ -126,9 +126,9 @@ impl<State> Request<State> {
/// assert_eq!(req.header(&"X-Forwarded-For".parse().unwrap()), Some(&vec!["127.0.0.1".parse().unwrap()]));
/// Ok("")
/// });
/// app.listen("127.0.0.1:8080").await?;
/// app.listen("127.0.0.1:8080").await
/// #
/// # Ok(()) })}
/// # })}
/// ```
pub fn header(
&self,
Expand Down Expand Up @@ -208,9 +208,9 @@ impl<State> Request<State> {
/// let _body: Vec<u8> = req.body_bytes().await.unwrap();
/// Ok("")
/// });
/// app.listen("127.0.0.1:8080").await?;
/// app.listen("127.0.0.1:8080").await
/// #
/// # Ok(()) })}
/// # })}
/// ```
pub async fn body_bytes(&mut self) -> std::io::Result<Vec<u8>> {
let mut buf = Vec::with_capacity(1024);
Expand Down Expand Up @@ -243,9 +243,9 @@ impl<State> Request<State> {
/// let _body: String = req.body_string().await.unwrap();
/// Ok("")
/// });
/// app.listen("127.0.0.1:8080").await?;
/// app.listen("127.0.0.1:8080").await
/// #
/// # Ok(()) })}
/// # })}
/// ```
pub async fn body_string(&mut self) -> std::io::Result<String> {
let body_bytes = self.body_bytes().await?;
Expand Down
8 changes: 4 additions & 4 deletions src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ impl Server<()> {
/// #
/// let mut app = tide::new();
/// app.at("/").get(|_| async move { Ok("Hello, world!") });
/// app.listen("127.0.0.1:8080").await?;
/// app.listen("127.0.0.1:8080").await
/// #
/// # Ok(()) }) }
/// # }) }
/// ```
pub fn new() -> Server<()> {
Self::with_state(())
Expand Down Expand Up @@ -196,9 +196,9 @@ impl<State: Send + Sync + 'static> Server<State> {
/// app.at("/").get(|req: Request<State>| async move {
/// Ok(format!("Hello, {}!", &req.state().name))
/// });
/// app.listen("127.0.0.1:8080").await?;
/// app.listen("127.0.0.1:8080").await
/// #
/// # Ok(()) }) }
/// # }) }
/// ```
pub fn with_state(state: State) -> Server<State> {
let mut server = Server {
Expand Down
3 changes: 1 addition & 2 deletions src/server/route.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,7 @@ impl<'a, State: 'static> Route<'a, State> {
/// async fn main() -> Result<(), std::io::Error> {
/// let mut app = tide::new();
/// app.at("/public/images").serve_dir("images/")?;
/// app.listen("127.0.0.1:8080").await?;
/// Ok(())
/// app.listen("127.0.0.1:8080").await
/// }
/// ```
pub fn serve_dir(&mut self, dir: impl AsRef<Path>) -> io::Result<()> {
Expand Down
4 changes: 2 additions & 2 deletions src/sse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
//! sender.send("fruit", "apple", None).await;
//! Ok(())
//! }));
//! app.listen("localhost:8080").await?;
//! # Ok(()) }) }
//! app.listen("localhost:8080").await
//! # }) }
//! ```

mod endpoint;
Expand Down