Skip to content
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

blocking::Client Local Response response.body().unwrap().into_string() returns Future<Output = Option<String>> #1573

Closed
DanielJoyce opened this issue Mar 12, 2021 · 5 comments

Comments

@DanielJoyce
Copy link

This makes it hard to use from sync tests. :)

0.5.0-dev

@DanielJoyce
Copy link
Author

With async client, you can't use into_string

let body = response.body().unwrap().into_string();
cannot move out of a shared reference
move occurs because value has type `rocket::response::Body<Pin<Box<dyn response::response::AsyncReadSeek + std::marker::Send>>, Pin<Box<dyn rocket::tokio::io::AsyncRead + std::marker::Send>>>`, which does not implement the `Copy`

@SergioBenitez
Copy link
Member

That's what into_string() is for. Please read the docs a bit more carefully.

@DanielJoyce
Copy link
Author

DanielJoyce commented Mar 12, 2021

I'm reading the docs carefully, into_string() fails for blocking client because it returns a future, and so can't be used in #[test]

If you try and use blocking in a regular #[test] block there is another compiler error.

when I try and use #[async_test], i must use async client, and then it fails with the following for into_string()

let body = response.body().unwrap().into_string().await

Future cannot be sent between threads safely
the trait `std::marker::Sync` is not implemented for `dyn response::response::AsyncReadSeek + std::marker::Send`rustc
main.rs(1, 1): required by a bound in this
lib.rs(166, 66): required by this bound in `async_test`
project_folders.rs(272, 20): future is not `Send` as this value is used across an await
project_folders.rs(272, 64): `response.body().unwrap()` is later dropped here

@DanielJoyce
Copy link
Author

DanielJoyce commented Mar 12, 2021

Oh, there are two into_string(), one on response, and one on body. To me, if I want the body as a string, I should call it on body.

It looks like body.into_string() might have wrong visibility then.

@SergioBenitez
Copy link
Member

SergioBenitez commented Mar 12, 2021

It does not have the wrong visibility. The body is retrievable should you need to inspect it directly. If you need to simply read it, we provide helper methods on LocalResponse. All of the documentation, including the guide, the module levels docs, and the struct level docs point to these helper methods. None point to using body() unless it's necessary, in which case a precise example is provided for how to do so, and so I am surprised you reached for it.

I don't believe there is anything to be done here, so I'm closing this out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants