pub async fn send_and_expect(&mut self, request: rtsp_types::Request<Body>, retrying: bool) -> std::result::Result<rtsp_types::Response<Body>, ClientActionError> {
I get:
recursion in an `async fn` requires boxing
recursive `async fn`
note: a recursive `async fn` must be rewritten to return a boxed `dyn Future`rustc(E0733)
I found https://rust-lang.github.io/async-book/07_workarounds/04_recursion.html but it is for a function that does not use async
.
What should be the way here?
I found Why recursive async functions require 'static parameters in Rust? and I changed my function to
pub fn send_and_expect(&mut self, request: rtsp_types::Request<Body>, retrying: bool)
-> Pin<Box<dyn Future <Output = std::result::Result<rtsp_types::Response<Body>, ClientActionError>>>> {
but now I cannot use await
inside my funtion. Also, how do I return things?
For example:
return Box::pin(Err(ClientActionError::CSeqMissing))
won't work
UPDATE:
Based on the answer, below, I get this on the recursion call:
194 | }.boxed()
| ^^^^^ future created by async block is not `Send`
|
= help: the trait `std::marker::Send` is not implemented for `dyn futures::Future<Output = std::result::Result<rtsp_types::Response<Body>, ClientActionError>>`
note: future is not `Send` as it awaits another future which is not `Send`
--> src/client.rs:170:36
|
170 | ... return self.send_and_expect(request.clone(), true).await;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ await occurs here on type `Pin<Box<dyn futures::Future<Output = std::result::Result<rtsp_types::Response<Body>, ClientActionError>>>>`, which is not `Send`
UPDATE 2:
error[E0759]: `self` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirement
--> src/client.rs:156:20
|
154 | pub fn send_and_expect(&mut self, request: rtsp_types::Request<Body>, retrying: bool)
| --------- this data with an anonymous lifetime `'_`...
155 | -> Pin<Box<dyn Future<Output = std::result::Result<rtsp_types::Response<Body>, ClientActionError>>+ Send>> {
156 | async move {
| ____________________^
157 | | let expected_cseq_header_value = rtsp_types::HeaderName::from_static_str("cseq").unwrap();
158 | | let expected_cseq = request.header(&expected_cseq_header_value);
159 | | let expected_cseq = match expected_cseq {
... |
193 | | Err(ClientActionError::Teardown)
194 | | }.boxed()
| |_________^ ...is captured here, requiring it to live as long as `'static`
|
help: to declare that the trait object captures data from argument `self`, you can add an explicit `'_` lifetime bound
|
155 | -> Pin<Box<dyn Future<Output = std::result::Result<rtsp_types::Response<Body>, ClientActionError>>+ Send + '_>> {
| ^^^^