Skip to content
New issue

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

Feature request: Custom destructuring #78154

Closed
LoganDark opened this issue Oct 20, 2020 · 8 comments
Closed

Feature request: Custom destructuring #78154

LoganDark opened this issue Oct 20, 2020 · 8 comments

Comments

@LoganDark
Copy link

Let's say I have this struct, Vec2:

#[derive(Copy, Clone, PartialEq, Debug)]
pub struct Vec2 {
	x: f32,
	y: f32
}

And I also a tuple containing two Vec2s:

let t: (Vec2, Vec2) = ...;

Right now, I have to do this to destructure it, which is really long and cumbersome to type:

let (Vec2 { x: mut x1, y: mut y1 }, Vec2 { x: mut x2, y: mut y2 }) = t;

I thought it would be a lot nicer if I could do this instead:

let ((mut x1, mut y1), (mut x2, mut y2)) = t;

But after asking for help in the Rust Discord, it looks like this is impossible!

Should support for custom destructuring like this be added? Is it even possible?

It could work like this:

impl Destructure<(f32, f32)> for Vec2 {
	fn destructure(self) -> (f32, f32) {
		(self.x, self.y)
	}
}

impl DestructureRef<(&f32, &f32)> for Vec2 {
	fn destructure_ref(&self) -> (&f32, &f32) {
		(self.x, self.y)
	}
}

impl DestructureMut<(&mut f32, &mut f32)> for Vec2 {
	fn destructure_mut(&mut self) -> (&mut f32, &mut f32) {
		(self.x, self.y)
	}
}

Or it could use the existing Into/AsRef/AsMut traits instead, thoughts?

@jonas-schievink
Copy link
Contributor

Hi! Additions or changes to the language need to go through our RFC process. Before an RFC is written, the feature can also be discussed in our internals forum to find other people interested in it.

Closing in favor of an RFC.

@LoganDark
Copy link
Author

LoganDark commented Oct 20, 2020

Why can't the discussion be here? Other feature requests are already being discussed on GitHub, like https://github.com/rust-lang/rust/issues/78064, which is only two days old (and also does not have an RFC yet).

Fun fact, I actually intended to post the feature request there instead of here - but I actually couldn't find the internals forum, and got confused after seeing that the users forum had no feature requests (/language design) category! I had no idea the two were separate :/

@Lonami
Copy link
Contributor

Lonami commented Oct 20, 2020

It depends on the magnitude of the feature request, and the team decides what requests are too large to be discussed here. #78161 should help future users find IRLO for largeish requests.

@LoganDark
Copy link
Author

So that is the issue then, this request is too large? Could you please elaborate more on why?

@jonas-schievink
Copy link
Contributor

Why can't the discussion be here?

The RFCs repo and internals forum were deliberately created to house design work and discussion. This issue tracker is meant mostly for bugs.

Other feature requests are already being discussed on GitHub, like #78064, which is only two days old (and also does not have an RFC yet).

We sometimes don't consistently apply rules to the issue tracker, because they aren't written down anywhere and people often miss things (since it is almost impossible to keep up with every issue that is filed here).

@LoganDark
Copy link
Author

We sometimes don't consistently apply rules to the issue tracker, because they aren't written down anywhere and people often miss things (since it is almost impossible to keep up with every issue that is filed here).

That sounds a little unfair, then. Fine, I will go post a duplicate on the forum. Eventually.

@Lonami
Copy link
Contributor

Lonami commented Oct 20, 2020

this request is too large? Could you please elaborate more on why?

I have no authority here, it's just how I see things normally work :P but probably the main reason is, as jonas pointed out, that it's hard to keep up and it's all subjective. In any case don't take this personally, a quick search for the text above reveals more issues closed with the same reasoning.

@LoganDark
Copy link
Author

A few of those issues were obviously joke requests (like "remove semicolons" begging Rust to be more like python). Most likely the comment was used there to close the issue more professionally than "not in a million years". I don't see how my issue fits into that category, but in any case there's no point in arguing about it here. I'll move to the forum.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants