Open cyqsimon opened 11 months ago
The generic API might have become more feasible since GAT is stable now:
pub trait Map {
type Output<Input>;
fn map<Input>(&self, input: Input) -> Self::Output<Input>;
}
impl tuple {
pub fn map<M: Map>(self, m: &M) -> tuple;
}
This should probably be an ACP (API change proposal) over at https://github.com/rust-lang/libs-team/issues if fleshed out a bit.
Not sure what's the "formal" syntax to express "for tuples of any size", so I'll use 2-tuples here in my examples.
TL;DR, I want this:
Much like how
Option::as_ref
converts from&Option<T>
toOption<&T>
.Besides being generally useful, it also allows for more readable code in some circumstances:
It looks like the map isn't doing anything, but due to how destructuring works, it's actually necessary. This would be much clearer: