Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@copybara-service
Copy link

Add the Ctor! convenience/abstraction macro we've talked about.

The purpose of this macro is to hide the impl trait. This makes it easier to change over time, and makes the caller interface much easier to work with, requiring less mindless repetitive typing.

We've said that a snippet of C++ should not require 5x as many tokens to type as the Rust equivalent when using Crubit. So specifying that you return a type, where in C++ it's Foo, in Rust it's -> Ctor<Output=Foo, Error=std::convert::Infallible>. 1 token vs 16 tokens!

This CL brings it down to -> ctor::Ctor![Foo], 8 tokens. That's about as minimal as we can make it. (Fortunately I think the 5x rule was aimed at function calls, not defining functions, or we'd be in trouble!)

Note that it doesn't work if you need use<'a, Self> and such. I tried, but that was really hard to parse if the macro is to have a really even remotely reasonable syntax. (It needs to support both lifetimes and types, and so on.) Instead, opted to just leave them out. They aren't necessary in Rust 2024.

The purpose of this macro is to hide the impl trait. This makes it easier to change over time, and makes the caller interface much easier to work with, requiring less mindless repetitive typing.

We've said that a snippet of C++ should not require 5x as many tokens to type as the Rust equivalent when using Crubit. So specifying that you return a type, where in C++ it's `Foo`, in Rust it's `-> Ctor<Output=Foo, Error=std::convert::Infallible>`. 1 token vs 16 tokens!

This CL brings it down to `-> ctor::Ctor![Foo]`, 8 tokens. That's about as minimal as we can make it. (Fortunately I think the 5x rule was aimed at function calls, not defining functions, or we'd be in trouble!)

Note that it doesn't work if you need `use<'a, Self>` and such. I tried, but that was really hard to parse if the macro is to have a really even remotely reasonable syntax. (It needs to support both lifetimes and types, and so on.) Instead, opted to just leave them out. They aren't necessary in Rust 2024.

PiperOrigin-RevId: 841962605
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

Successfully merging this pull request may close these issues.

1 participant