这是indexloc提供的服务,不要输入任何密码
Skip to content

Remove lifetime notation on Request #12

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

Merged
merged 2 commits into from
Jul 9, 2024
Merged
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
2 changes: 1 addition & 1 deletion crates/tuono/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tuono"
version = "0.4.4"
version = "0.4.5"
edition = "2021"
authors = ["V. Ageno <valerioageno@yahoo.it>"]
description = "The react/rust fullstack framework"
Expand Down
4 changes: 2 additions & 2 deletions crates/tuono_lib/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tuono_lib"
version = "0.4.4"
version = "0.4.5"
edition = "2021"
authors = ["V. Ageno <valerioageno@yahoo.it>"]
description = "The react/rust fullstack framework"
Expand Down Expand Up @@ -31,7 +31,7 @@ regex = "1.10.5"
either = "1.13.0"
tower-http = {version = "0.5.2", features = ["fs"]}

tuono_lib_macros = {path = "../tuono_lib_macros", version = "0.4.4"}
tuono_lib_macros = {path = "../tuono_lib_macros", version = "0.4.5"}
# Match the same version used by axum
tokio-tungstenite = "0.21.0"
futures-util = { version = "0.3", default-features = false, features = ["sink", "std"] }
Expand Down
6 changes: 3 additions & 3 deletions crates/tuono_lib/src/catch_all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ pub async fn catch_all(
Path(params): Path<HashMap<String, String>>,
request: Request,
) -> Html<String> {
let pathname = &request.uri();
let headers = &request.headers();
let pathname = request.uri();
let headers = request.headers();

let req = crate::Request::new(pathname, headers, params);
let req = crate::Request::new(pathname.to_owned(), headers.to_owned(), params);

// TODO: remove unwrap
let payload = Payload::new(&req, &"").client_payload().unwrap();
Expand Down
4 changes: 2 additions & 2 deletions crates/tuono_lib/src/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub struct Payload<'a> {
}

impl<'a> Payload<'a> {
pub fn new(req: &Request<'a>, props: &'a dyn Serialize) -> Payload<'a> {
pub fn new(req: &Request, props: &'a dyn Serialize) -> Payload<'a> {
Payload {
router: req.location(),
props,
Expand Down Expand Up @@ -186,7 +186,7 @@ mod tests {
);
MANIFEST.get_or_init(|| manifest_mock);
let location = Location::from(
&uri.unwrap_or("http://localhost:3000/")
uri.unwrap_or("http://localhost:3000/")
.parse::<Uri>()
.unwrap(),
);
Expand Down
20 changes: 8 additions & 12 deletions crates/tuono_lib/src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ impl Location {
}
}

impl<'a> From<&'a Uri> for Location {
fn from(uri: &Uri) -> Self {
impl From<Uri> for Location {
fn from(uri: Uri) -> Self {
Location {
href: uri.to_string(),
pathname: uri.path().to_string(),
Expand All @@ -33,18 +33,14 @@ impl<'a> From<&'a Uri> for Location {
}

#[derive(Debug, Clone)]
pub struct Request<'a> {
uri: &'a Uri,
pub headers: &'a HeaderMap,
pub struct Request {
uri: Uri,
pub headers: HeaderMap,
pub params: HashMap<String, String>,
}

impl<'a> Request<'a> {
pub fn new(
uri: &'a Uri,
headers: &'a HeaderMap,
params: HashMap<String, String>,
) -> Request<'a> {
impl Request {
pub fn new(uri: Uri, headers: HeaderMap, params: HashMap<String, String>) -> Request {
Request {
uri,
headers,
Expand All @@ -53,6 +49,6 @@ impl<'a> Request<'a> {
}

pub fn location(&self) -> Location {
Location::from(self.uri)
Location::from(self.uri.to_owned())
}
}
2 changes: 1 addition & 1 deletion crates/tuono_lib_macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tuono_lib_macros"
version = "0.4.4"
version = "0.4.5"
edition = "2021"
description = "The react/rust fullstack framework"
keywords = [ "react", "typescript", "fullstack", "web", "ssr"]
Expand Down
12 changes: 6 additions & 6 deletions crates/tuono_lib_macros/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ pub fn handler_core(_args: TokenStream, item: TokenStream) -> TokenStream {
State(client): State<tuono_lib::reqwest::Client>,
request: tuono_lib::axum::extract::Request
) -> impl IntoResponse {
let pathname = &request.uri();
let headers = &request.headers();
let pathname = request.uri();
let headers = request.headers();

let req = tuono_lib::Request::new(pathname, headers, params);
let req = tuono_lib::Request::new(pathname.to_owned(), headers.to_owned(), params);

#fn_name(req.clone(), client).await.render_to_string(req)
}
Expand All @@ -32,10 +32,10 @@ pub fn handler_core(_args: TokenStream, item: TokenStream) -> TokenStream {
State(client): State<tuono_lib::reqwest::Client>,
request: tuono_lib::axum::extract::Request
) -> impl IntoResponse{
let pathname = &request.uri();
let headers = &request.headers();
let pathname = request.uri();
let headers = request.headers();

let req = tuono_lib::Request::new(pathname, headers, params);
let req = tuono_lib::Request::new(pathname.to_owned(), headers.to_owned(), params);

#fn_name(req.clone(), client).await.json()
}
Expand Down
10 changes: 5 additions & 5 deletions docs/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ struct Pokemon {
}

#[tuono_lib::handler]
async fn get_all_pokemons(_req: Request<'_>, fetch: Client) -> Response {
async fn get_all_pokemons(_req: Request, fetch: Client) -> Response {
return match fetch.get(ALL_POKEMON).send().await {
Ok(res) => {
let data = res.json::<Pokemons>().await.unwrap();
Expand Down Expand Up @@ -343,7 +343,7 @@ struct Pokemon {
}

#[tuono_lib::handler]
async fn get_pokemon(req: Request<'_>, fetch: Client) -> Response {
async fn get_pokemon(req: Request, fetch: Client) -> Response {
// The param `pokemon` is defined in the route filename [pokemon].rs
let pokemon = req.params.get("pokemon").unwrap();

Expand Down Expand Up @@ -486,7 +486,7 @@ struct Pokemon {
}

#[tuono_lib::handler]
async fn get_pokemon(req: Request<'_>, fetch: Client) -> Response {
async fn get_pokemon(req: Request, fetch: Client) -> Response {
// The param `pokemon` is defined in the route filename [pokemon].rs
let pokemon = req.params.get("pokemon").unwrap();

Expand Down Expand Up @@ -529,7 +529,7 @@ struct Pokemon {
}

#[tuono_lib::handler]
async fn get_all_pokemons(_req: Request<'_>, fetch: Client) -> Response {
async fn get_all_pokemons(_req: Request, fetch: Client) -> Response {
return match fetch.get(ALL_POKEMON).send().await {
Ok(res) => {
let data = res.json::<Pokemons>().await.unwrap();
Expand Down Expand Up @@ -560,7 +560,7 @@ First let's create a new route by just creating an new file `/pokemons/GOAT.rs`
use tuono_lib::{reqwest::Client, Request, Response};

#[tuono_lib::handler]
async fn redirect_to_goat(_: Request<'_>, _: Client) -> Response {
async fn redirect_to_goat(_: Request, _: Client) -> Response {
// Of course the GOAT is mewtwo - feel free to select your favourite 😉
Response::Redirect("/pokemons/mewtwo".to_string())
}
Expand Down
1 change: 1 addition & 0 deletions examples/tuono/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ path = ".tuono/main.rs"

[dependencies]
tuono_lib = { path = "../../crates/tuono_lib/"}
serde = { version = "1.0.202", features = ["derive"] }

3 changes: 2 additions & 1 deletion examples/tuono/src/routes/index.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use serde::Serialize;
use tuono_lib::reqwest;
use tuono_lib::{Props, Request, Response};

#[derive(Serialize)]
Expand All @@ -7,7 +8,7 @@ struct MyResponse<'a> {
}

#[tuono_lib::handler]
async fn get_server_side_props(_req: Request<'_>, _fetch: reqwest::Client) -> Response {
async fn get_server_side_props(_req: Request, _fetch: reqwest::Client) -> Response {
Response::Props(Props::new(MyResponse {
subtitle: "The react / rust fullstack framework",
}))
Expand Down
2 changes: 1 addition & 1 deletion examples/tutorial/src/routes/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct Pokemon {
}

#[tuono_lib::handler]
async fn get_all_pokemons(_req: Request<'_>, fetch: Client) -> Response {
async fn get_all_pokemons(_req: Request, fetch: Client) -> Response {
match fetch.get(ALL_POKEMON).send().await {
Ok(res) => {
let data = res.json::<Pokemons>().await.unwrap();
Expand Down
2 changes: 1 addition & 1 deletion examples/tutorial/src/routes/pokemons/GOAT.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
use tuono_lib::{reqwest::Client, Request, Response};

#[tuono_lib::handler]
async fn redirect_to_goat(_: Request<'_>, _: Client) -> Response {
async fn redirect_to_goat(_: Request, _: Client) -> Response {
Response::Redirect("/pokemons/mewtwo".to_string())
}
2 changes: 1 addition & 1 deletion examples/tutorial/src/routes/pokemons/[pokemon].rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct Pokemon {
}

#[tuono_lib::handler]
async fn get_pokemon(req: Request<'_>, fetch: Client) -> Response {
async fn get_pokemon(req: Request, fetch: Client) -> Response {
// The param `pokemon` is defined in the route filename [pokemon].rs
let pokemon = req.params.get("pokemon").unwrap();

Expand Down
2 changes: 1 addition & 1 deletion packages/fs-router-vite-plugin/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tuono-fs-router-vite-plugin",
"version": "0.4.4",
"version": "0.4.5",
"description": "Plugin for the tuono's file system router. Tuono is the react/rust fullstack framework",
"scripts": {
"dev": "vite build --watch",
Expand Down
2 changes: 1 addition & 1 deletion packages/lazy-fn-vite-plugin/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tuono-lazy-fn-vite-plugin",
"version": "0.4.4",
"version": "0.4.5",
"description": "Plugin for the tuono's lazy fn. Tuono is the react/rust fullstack framework",
"scripts": {
"dev": "vite build --watch",
Expand Down
2 changes: 1 addition & 1 deletion packages/tuono/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tuono",
"version": "0.4.4",
"version": "0.4.5",
"description": "The react/rust fullstack framework",
"scripts": {
"dev": "vite build --watch",
Expand Down