You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Sep 12, 2024. It is now read-only.
I'm not sure if this is the right forum, if not, I'm sorry. Anyway, I had some trouble with lifetime specifiers where the compile errors are a bit strange.
The idea is to take an iterator of positions and return and iterator of positions and their contents, however I couldn't figure out what went wrong when returning an iterator. Just removing the collect and changing the return type leads to:
error[[E0700]](https://doc.rust-lang.org/stable/error_codes/E0700.html): hidden type for `impl IntoIterator<Item = Option<(Pos, CellState)>>` captures lifetime that does not appear in bounds
and recommends adding a lifetime specifier + '_, that addition in turn leads to this error:
error[[E0311]](https://doc.rust-lang.org/stable/error_codes/E0311.html): the associated type `<impl IntoIterator<Item = Pos> as IntoIterator>::IntoIter` may not live long enough
Now, the solution is to ensure pos and m live for at least as long as the return value, which is done by adding lifetime specifiers on the arguments and return value like this:
pub fn pos_iter_to_cells<'a>(
pos: impl IntoIterator<Item = Pos> + 'a,
m: &'a Board,
) -> impl IntoIterator<Item = Option<(Pos, CellState)>> + 'a {
let ret = pos.into_iter().map(|p @ Pos { x, y }| match m.get(x) {
Some(v) => match v.get(y) {
None => None,
Some(&a) => Some((p, a)),
},
None => None,
});
return ret;
}
However getting there for me required going and asking reddit. It might be that I missed some documentation, not sure. Anyway made a rust-lang-gist with all the types required. Here is the discussion on reddit
The text was updated successfully, but these errors were encountered:
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Hi,
I'm not sure if this is the right forum, if not, I'm sorry. Anyway, I had some trouble with lifetime specifiers where the compile errors are a bit strange.
The original code looks like this:
The idea is to take an iterator of positions and return and iterator of positions and their contents, however I couldn't figure out what went wrong when returning an iterator. Just removing the collect and changing the return type leads to:
and recommends adding a lifetime specifier
+ '_
, that addition in turn leads to this error:Now, the solution is to ensure
pos
andm
live for at least as long as the return value, which is done by adding lifetime specifiers on the arguments and return value like this:However getting there for me required going and asking reddit. It might be that I missed some documentation, not sure. Anyway made a rust-lang-gist with all the types required. Here is the discussion on reddit
The text was updated successfully, but these errors were encountered: