Skip to content

Instantly share code, notes, and snippets.

@LukasKalbertodt
Last active June 21, 2017 00:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LukasKalbertodt/84181baba864d58d4a09d966ac2d9ebc to your computer and use it in GitHub Desktop.
Save LukasKalbertodt/84181baba864d58d4a09d966ac2d9ebc to your computer and use it in GitHub Desktop.
error[E0495]: cannot infer an appropriate lifetime for lifetime parameter in function call due to conflicting requirements
--> src/lib.rs:459:23
|
459 | Some(&mut self.sv.data[1])
| ^^^^^^^^^^^^^^^
|
note: first, the lifetime cannot outlive the lifetime 'b as defined on the body at 450:52...
--> src/lib.rs:450:53
|
450 | fn next<'b>(&'b mut self) -> Option<Self::Item> {
| _____________________________________________________^
451 | | if self.pos == self.sv.data.len() {
452 | | None
453 | | } else {
... |
460 | | }
461 | | }
| |_____^
note: ...so that reference does not outlive borrowed content
--> src/lib.rs:459:23
|
459 | Some(&mut self.sv.data[1])
| ^^^^^^^^^^^^
note: but, the lifetime must be valid for the lifetime 'a as defined on the body at 450:52...
--> src/lib.rs:450:53
|
450 | fn next<'b>(&'b mut self) -> Option<Self::Item> {
| _____________________________________________________^
451 | | if self.pos == self.sv.data.len() {
452 | | None
453 | | } else {
... |
460 | | }
461 | | }
| |_____^
note: ...so that types are compatible (expected std::iter::Iterator, found std::iter::Iterator)
--> src/lib.rs:450:53
|
450 | fn next<'b>(&'b mut self) -> Option<Self::Item> {
| _____________________________________________________^
451 | | if self.pos == self.sv.data.len() {
452 | | None
453 | | } else {
... |
460 | | }
461 | | }
| |_____^
pub struct IterMut<'a, T: 'a> {
sv: &'a mut StableVec<T>,
pos: usize,
}
impl<'a, T> Iterator for IterMut<'a, T> {
type Item = &'a mut T;
fn next<'b>(&'b mut self) -> Option<Self::Item> {
if self.pos == self.sv.data.len() {
None
} else {
while self.sv.deleted[self.pos] {
self.pos += 1;
}
self.pos += 1;
Some(&mut self.sv.data[1]) // <-- `self.sv.data` is a `Vec<T>`
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment