Get multiple &mut from a vector, or any iterator

A tangent, but…would this also trip #[forbid(unsafe_code)]-using crates? Meaning that anything that wants to say "I never use unsafe myself" is forbidden from saying "my Eq is trustworthy"? That would seem…unfortunate.

This seems correct for any hypothetical Trusted… trait: The trustworthiness is a property that can’t be checked by the compiler but is relied on for memory safety— In this case, a bad Eq implementation could cause an &mut aliasing violation.

If somebody wanted to push this idea forward, though, we’d probably want a safe derive for TrustedEq for the case that all members also implement TrustedEq.

There could be a blanket impl for T: StructuralEq, which you get via derived Eq -- this is safe and trusted enough for patterns already. Further TrustedEq can then be unsafe.

1 Like

Since this is IRLO, it might as well just use [const { None }; LEN], as that's in p-FCP.

1 Like

That's definitely an interesting idea. I think that could make a lot of sense actually.

I just saw that there is a PR for a slice version of this too:

It's not as broadly applicable as find_many on iterators, but it may be good enough for some.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.