We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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:
let ref_of_tuple: &(u8, u16) = &(6, 9); let tuple_of_refs: (&u8, &u16) = ref_of_tuple.as_ref(); assert_eq!(tuple_of_refs, (&6, &9));
Much like how Option::as_ref converts from &Option<T> to Option<&T>.
Option::as_ref
&Option<T>
Option<&T>
Besides being generally useful, it also allows for more readable code in some circumstances:
fn convert(from: &[(u8, u16)]) -> Vec<(&u8, &u16)> { from.iter() .map(|(a, b)| (a, b)) // huh? .collect() }
It looks like the map isn't doing anything, but due to how destructuring works, it's actually necessary. This would be much clearer:
fn convert(from: &[(u8, u16)]) -> Vec<(&u8, &u16)> { from.iter() .map(AsRef::as_ref) .collect() }
The text was updated successfully, but these errors were encountered:
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; }
Sorry, something went wrong.
This should probably be an ACP (API change proposal) over at https://github.com/rust-lang/libs-team/issues if fleshed out a bit.
No branches or pull requests
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:
The text was updated successfully, but these errors were encountered: