Skip to content

Commit d5fc739

Browse files
committed
fix: more generics
- pages now return impl IntoResponse instead of Response - tokio features instead of full, now rt-multi-thread and macros
1 parent 0fb350a commit d5fc739

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "stoic-quotes"
3-
version = "0.3.5"
3+
version = "0.3.6"
44
edition = "2021"
55
authors = ["Jose Storopoli <[email protected]>"]
66
description = "Stoic quotes API backend"
@@ -15,7 +15,7 @@ lazy_static = "1"
1515
rand = "0.8"
1616
serde = { version = "1", features = ["derive"] }
1717
serde_json = "1"
18-
tokio = { version = "1", features = ["full"] }
18+
tokio = { version = "1", features = ["rt-multi-thread", "macros"] }
1919
tower-http = { version = "0.5", features = ["tracing", "trace", "fs"] }
2020
tracing = "0.1"
2121
tracing-subscriber = "0.3"

src/app.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Module that has functions that handles the Axum [`Router`].
22
33
use crate::pages::{plain_quote, quote, root};
4-
use axum::{http::header::USER_AGENT, http::Request, response::Response, routing::get, Router};
4+
use axum::{http::header::USER_AGENT, http::Request, response::IntoResponse, routing::get, Router};
55
use std::{env::current_dir, path::PathBuf};
66
use tower_http::{services::ServeDir, trace::TraceLayer};
77
use tracing::info;
@@ -10,7 +10,7 @@ use tracing::info;
1010
/// If the user agent is `curl` or `wget`,
1111
/// return a plain quote.
1212
/// Otherwise, return the root page.
13-
async fn handle_user_agent<T>(req: Request<T>) -> Response {
13+
async fn handle_user_agent<T>(req: Request<T>) -> impl IntoResponse {
1414
let header = Request::headers(&req);
1515
let user_agent: String = if let Some(user_agent) = header.get(USER_AGENT) {
1616
user_agent.clone().to_str().unwrap().to_string()
@@ -21,9 +21,9 @@ async fn handle_user_agent<T>(req: Request<T>) -> Response {
2121
info!("got user agent: {user_agent}");
2222

2323
if user_agent.contains("curl") || user_agent.contains("Wget") {
24-
plain_quote().await
24+
plain_quote().await.into_response()
2525
} else {
26-
root().await
26+
root().await.into_response()
2727
}
2828
}
2929

src/pages.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,20 +49,20 @@ struct QuoteTemplate {
4949
}
5050

5151
/// Returns the rendered askama template for the root HTML element.
52-
pub async fn root() -> Response {
52+
pub async fn root() -> impl IntoResponse {
5353
let template = IndexTemplate {};
5454
HtmlTemplate(template).into_response()
5555
}
5656

5757
/// Returns the rendered askama template for a random quote HTML element.
58-
pub async fn quote() -> Response {
58+
pub async fn quote() -> impl IntoResponse {
5959
let Quote { text, author } = random_quote();
6060
let template = QuoteTemplate { text, author };
6161
HtmlTemplate(template).into_response()
6262
}
6363

6464
/// Returns a plain text random quote without any HTML.
65-
pub async fn plain_quote() -> Response {
65+
pub async fn plain_quote() -> impl IntoResponse {
6666
let Quote { text, author } = random_quote();
6767
let formatted_quote: String = format!("{text}\n\n - {author}\n");
6868
Html(formatted_quote).into_response()

0 commit comments

Comments
 (0)