Skip to content

Instantly share code, notes, and snippets.

@Gottox
Created January 20, 2020 07:58
Show Gist options
  • Save Gottox/fa0abf92249193278beb656597833d5e to your computer and use it in GitHub Desktop.
Save Gottox/fa0abf92249193278beb656597833d5e to your computer and use it in GitHub Desktop.
error[E0495]: cannot infer an appropriate lifetime for autoref due to conflicting requirements
--> src/client.rs:95:76
|
95 | let other_pages = iter(1 .. total_pages).then(move |n| cloned_self.page::<E>(n));
| ^^^^
|
note: first, the lifetime cannot outlive the lifetime `'_` as defined on the body at 95:55...
--> src/client.rs:95:55
|
95 | let other_pages = iter(1 .. total_pages).then(move |n| cloned_self.page::<E>(n));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...so that closure can access `cloned_self`
--> src/client.rs:95:64
|
95 | let other_pages = iter(1 .. total_pages).then(move |n| cloned_self.page::<E>(n));
| ^^^^^^^^^^^
note: but, the lifetime must be valid for the method call at 95:27...
--> src/client.rs:95:27
|
95 | let other_pages = iter(1 .. total_pages).then(move |n| cloned_self.page::<E>(n));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...so type `futures_util::stream::stream::then::Then<futures_util::stream::iter::Iter<std::ops::Range<usize>>, impl core::future::future::Future, [closure@src/client.rs:95:55: 95:88 cloned_self:client::Client]>` of expression is valid during the expression
--> src/client.rs:95:27
|
95 | let other_pages = iter(1 .. total_pages).then(move |n| cloned_self.page::<E>(n));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error
For more information about this error, try `rustc --explain E0495`.
error: could not compile `lexoffice`.
To learn more, run the command again with --verbose.
// ...
async fn stream<E>(
&self,
) -> Box<dyn Stream<Item = Result<Page<E>, Box<dyn Error>>>>
where
E: PaginationEndpoint + DeserializeOwned + 'static,
{
use std::iter::once;
use futures::stream::iter;
let first_page = match self.page::<E>(0).await {
Ok(x) => x,
x => return Box::new(iter(once(x))),
};
let total_pages = first_page.total_pages;
let cloned_self = self.clone();
let other_pages = iter(1 .. total_pages).then(move |n| cloned_self.page::<E>(n));
Box::new(iter(once(Ok(first_page))).chain(other_pages))
}
// ...
@Gottox
Copy link
Author

Gottox commented Jan 20, 2020

Line 18 represents Line 95 in the error message.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment