-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Julian Orth
committed
Mar 6, 2015
1 parent
093c526
commit ad305ac
Showing
1 changed file
with
3 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Can you say something like this:
//
The straightforward marker would be&'a mut Vec<T>
. If we were writing this in safe code, that's what we would have after all. However, that would also induce invariance onT
, which given thatDrain
only ever extracts values ofT
is stricter than necessary. Therefore, we use this more subtle formulation, which uses a&'a ()
marker to bind the lifetime securing the vector, and which uses a second marker to express that we have a way of producingT
instances that we are going to employ. This gives covariance inT
.Feel free to make it less wordy. :) The main thing I am interested in is expressing why we avoided the straightforward thing and why covariance is believed to be correct. (You might also indicate a brief note that this similarly implies
T:'a
is not needed.)