Experimented with Unsafe for the first time with modifications to FuturesUnordered

I've modified FuturesUnordered to create the MappedFutures library. I would appreciate any feedback on the usefulness of this library and its soundness.

Whereas FuturesUnordered can be added to with push() and futures cannot be removed except by polling them with next(). MappedFutures can be added to with insert(), they can be retrieved for mutation with get_mut(), and they can be cancelled with remove() or the unsafe remove_pinned(), of which only the latter returns the future.

Making the changes was difficult, but I've written tests that now run without error, but of course that does not guarantee that the changes are sound in all circumstances. If anyone out there has time and interest, any reports of unsoundness in the library would be greatly appreciated.

With the exception of the new methods, the library is changed mainly to add the K: Hash + Eq +Clone generic to all the library's types, and to add/remove tasks when appropriate from the new HashMap field of MappedFutures.

Edit: I've published the crate here https://crates.io/crates/mapped_futures

On a first glance, given your description of the API, I’d be wary of get_mut and question whether or not it unsoundly allows getting &mut Fut (instead of Pin<&mut Fut>) reference to a Fut that’s supposed to be considered pinned. Sorry for the vague statement, I don’t have time to test that at this moment.

Good point! I've changed the API so that get_mut() returns a pinned reference, and added unsafe get_mut_pinned() which requires that the originally inserted future had been pinned.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.