An example of the presence of the object-safe attribute Foo and the (potentially dangerous) attribute extension FooExt , implemented for all instances of Foo , is now becoming standard.
https://github.com/rust-lang/rfcs/pull/445
This is a problem for me in the case of Iterator<A> , since I have a library that overrides the default IteratorExt#last() method of the old iterator (the base library has an effective implementation of last() ). Now this is impossible, because for any A there will always be a contradictory implementation of IteratorExt , one that libcore already provides for all Iterator<A> .
iterator.rs:301:1: 306:2 error: conflicting implementations for trait `core::iter::IteratorExt` [E0119]
iterator.rs:301 impl<'a, K: Key> iter::IteratorExt<Vec<u8>> for ValueIterator<'a,K,Vec<u8>> { iterator.rs:302 fn last(&mut self) -> Option<Vec<u8>> { iterator.rs:303 self.seek_last(); iterator.rs:304 Some(self.value()) iterator.rs:305 } iterator.rs:306 } ...
Now, as far as I can see, I have two options:
- has its own trait and my own implementation of
last() . This would mean that it conflicts if IteratorExt imported, if not used carefully. It may also accidentally use an ineffective version of last() if using a version from IteratorExt . I would lose convenient access to IteratorExt . - has its own trait and name the method (
seek_last() ) in different ways. Disadvantage: I ask the user to study the vocabulary and always support my method compared to IteratorExt . Same problem: I would like to avoid accidentally using last() .
Is there any other, better, solution that I am missing?
iterator traits rust
Skade
source share