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

Suggestion: allow ignoring return value, overriding return type with () #6

Open
Boscop opened this issue Sep 29, 2018 · 0 comments
Open

Comments

@Boscop
Copy link

Boscop commented Sep 29, 2018

I use this crate a lot, also in combination with getset and ever since getset was modified to return &mut Self to allow chaining setters it requires changing all the delegated setters to also return &mut Member, which requires more typing and it leaks the member as mutable as a whole! Anyone can now completely modify the member through this public setter that is only supposed to allow the modification of 1 field of this member.
E.g. I want to write:

delegate_method! {
	impl Vibrato {
		lfo as Lfo:
		fn set_amplitude(&mut self, x: f32);
		fn set_freq(&mut self, x: f32);
	}
}

just like I was writing before getset switched to chaining setters, but it complains:

error: mismatched types
error: this error originates in a macro outside of the current crate
error: expected (), found mutable reference
error: expected `()` because of default return type
note: expected type `()` found type `&mut Lfo`
help: this error originates in a macro outside of the current crate
help: try adding a semicolon

Instead, I have to write:

delegate_method! {
	impl Vibrato {
		lfo as Lfo:
		fn set_amplitude(&mut self, x: f32) -> &mut Lfo;
		fn set_freq(&mut self, x: f32) -> &mut Lfo;
	}
}

But ideally I want delegate_method to allow me to write the first version and then ignore the return value of the delegated method, and return () instead.
Would it be possible to allow this in delegate_method? :)

It should be technically possible to always return () when no return type is specified (ignoring the value returned by the member's method), this will also work for methods that actually return () but also those that don't.

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

1 participant