-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Method cascades #6679
Comments
Is it possible to do this with a macro? It could have a syntax like:
And that would desugar to something like
Something along these lines could be useful to implement. |
This is like Clojure's |
It's a neat concept, and I think I actually prefer the look of it to method chaining, but I'm not sure if it's really necessary for Rust. |
This would be pretty cool indeed, as a syntax extension. |
If anybody is still interested in this, an official RFC should be filed. https://github.com/rust-lang/rfcs/blob/master/active/0001-rfc-process.md |
@huonw has implemented cascade operator with a macro that can be used as follow: let value = cascade!(Foo::new()
.. add_to_y(2.0)
.. x = 2
.. double_x()
.. z = "bar".to_strbuf()); I think it’s a great addition to the language compared to the quantity of code to merge, so please re-open. |
Before adding such a macro by default, I would like someone to demonstrate places in real Rust code that could benefit from it. An operator that is useful according to Dart's idioms is not automatically useful in Rust. Until then, this issue should not be re-opened. |
I've used a similar macro called On Sun, May 18, 2014 at 7:24 PM, Ben Striegel [email protected]:
|
(Especially since we have functional record update) On Sun, May 18, 2014 at 7:35 PM, Corey Richardson [email protected] wrote:
|
draw_push_clip as it currently is: https://gist.github.com/dharmatech/ded09b46ff700697aef6 How it would look with built-in support for method cascades: |
It doesn't need to be built-in to use it. The macro can be defined anywhere. On Mon, May 19, 2014 at 10:50 AM, dharmatech [email protected]:
|
rust-http - handle_request - after |
@dharmatech That draw_push_clip example looks really, really nice. More readable, less noise. |
Any news on this? |
Method cascades can currently be done with the cascade crate. Highly critical if you're working with certain types of APIs, such as constructing GTK widgets in gtk-rs. System76 uses it in all of their GTK applications. |
Use absolute path to Rust repo in ra_setup This will convert the path to the Rust repo to an absolute path. This is important for the clippy_lints/Cargo.toml file. Otherwise if a relative path is passed, rst-analyzer won't find the Rust repo, because it starts the relative path search from the clippy_lints dir, not the rust-clippy dir where the ra_setup command was run from. changelog: none
Consider method cascades for Rust.
The text was updated successfully, but these errors were encountered: