Skip to content

Commit 031036c

Browse files
weihangloseanmonstar
authored andcommitted
docs(examples): fix web_api shared client lifetime issue
1 parent e8c19fe commit 031036c

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

examples_disabled/web_api.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ async fn api_get_response() -> Result<Response<Body>, GenericError> {
7373
Ok(res)
7474
}
7575

76-
async fn response_examples(req: Request<Body>, client: &Client<HttpConnector>)
76+
async fn response_examples(req: Request<Body>, client: Client<HttpConnector>)
7777
-> Result<Response<Body>, GenericError>
7878
{
7979
match (req.method(), req.uri().path()) {
@@ -82,7 +82,7 @@ async fn response_examples(req: Request<Body>, client: &Client<HttpConnector>)
8282
Ok(Response::new(body))
8383
},
8484
(&Method::GET, "/test.html") => {
85-
client_request_response(client).await
85+
client_request_response(&client).await
8686
},
8787
(&Method::POST, "/json_api") => {
8888
api_post_response(req).await
@@ -115,7 +115,8 @@ async fn main() -> Result<(), GenericError> {
115115
let client = client.clone();
116116
async {
117117
Ok::<_, GenericError>(service_fn(move |req| {
118-
response_examples(req, &client)
118+
// Clone again to ensure that client outlives this closure.
119+
response_examples(req, client.to_owned())
119120
}))
120121
}
121122
});

0 commit comments

Comments
 (0)