Closed
Description
This code: (http://is.gd/tif86V)
struct Iter<'a>(&'a mut Vec<int>);
impl<'a> Iterator<&'a mut int> for Iter<'a> {
fn next(&mut self) -> Option<&'a mut int> {
self.0.as_mut_slice().get_mut(0)
}
}
Produces this:
<anon>:5:16: 5:30 error: cannot infer an appropriate lifetime for autoref due to conflicting requirements
<anon>:5 self.0.as_mut_slice().get_mut(0)
^~~~~~~~~~~~~~
<anon>:4:5: 6:6 help: consider using an explicit lifetime parameter as shown: fn next(&'a mut self) -> Option<&'a mut int>
<anon>:4 fn next(&mut self) -> Option<&'a mut int> {
<anon>:5 self.0.as_mut_slice().get_mut(0)
<anon>:6 }
I don't think there is anything unsafe with what I want to do (it's the exact same signature as MutItems
).
This code does work but is incompatible with the Iterator
trait definition: (http://is.gd/rMwbe6)
struct Iter<'a>(&'a mut Vec<int>);
impl<'a> Iter<'a> {
fn next<'c: 'a>(&'c mut self) -> Option<&'a mut int> {
self.0.as_mut_slice().get_mut(0)
}
}
Sorry if this is a duplicate.
Metadata
Metadata
Assignees
Labels
No labels