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

feat: add macro attr with_extensions #1380

Merged
merged 4 commits into from
Jun 3, 2024

Conversation

niklasad1
Copy link
Member

@niklasad1 niklasad1 commented May 28, 2024

Follow-up on #1306

Let's add on option to use Extensions in the API or not because it may be annoying to just mark it as used and would be nice not to break the previous API for existing users.

#[rpc(client, server)]
pub trait Rpc {
        // legacy
	#[method(name = "foo"])
	async fn async_method(&self, param_a: u8, param_b: String) -> u16>;

        // with extensions
	#[method(name = "with_ext", with_extensions)]
	async fn f(&self) -> bool;
}

impl RpcServer for () {
	async fn async_method(&self, param_a: u8, param_b: String) -> u16 {
            12
        }

	// NOTE: ext is injected here in the API
        async fn f(&self, ext: &Extensions: b: String) -> {
             ext.get::<u32>().is_ok()
        }
}

@niklasad1 niklasad1 requested a review from a team as a code owner May 28, 2024 18:13
Copy link
Collaborator

@jsdw jsdw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great to me; the attribute works well :)

#parsing
let _ = context.as_ref().#rust_method_name(pending, &ext, #params_seq);
#sub_err::None
if sub.with_extensions {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you collapse the if into else if following the recommendation from clippy, otherwise LGTM

@niklasad1 niklasad1 merged commit dc6a31b into master Jun 3, 2024
11 checks passed
@niklasad1 niklasad1 deleted the na-add-macro-attr-with-extensions branch June 3, 2024 12:34
@mudlee
Copy link

mudlee commented Jun 5, 2024

Nice work! May I ask when it'll approximately be released? :)

@niklasad1
Copy link
Member Author

niklasad1 commented Jun 5, 2024

Nice work! May I ask when it'll approximately be released? :)

We are "hoping" to get a new release out tomorrow

@niklasad1 niklasad1 mentioned this pull request Jun 6, 2024
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.

4 participants