Skip to content

FnOnce as Producer::send callback #273

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

Merged
merged 2 commits into from
Feb 18, 2025

Conversation

allevo
Copy link
Collaborator

@allevo allevo commented Feb 17, 2025

send method should accept a FnOnce because the callback is invoked only once, after the error or ack from the server.
This PR implements the check on the type system.

NB: this is a breaking change

    // A non copy structure
    struct Foo;

    let f = Foo;
    producer
        .send(
            Message::builder().body(b"message".to_vec()).build(),
            move |_| {
                // this callback is an FnOnce, so we can drop a value here
                drop(f);
                async {}
            },
        )
        .await
        .unwrap();

Implementation details:
This PR uses an enum to store an OnceProducerMessageWaiter or a SharedProducerMessageWaiter. Only the latter is clonable.

Other:
update fake to 4

@allevo allevo marked this pull request as ready for review February 17, 2025 11:43
Copy link

codecov bot commented Feb 17, 2025

Codecov Report

Attention: Patch coverage is 84.05797% with 11 lines in your changes missing coverage. Please review.

Project coverage is 90.29%. Comparing base (1977a2c) to head (66cf308).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/producer.rs 82.75% 10 Missing ⚠️
protocol/src/message/amqp/types/primitives/map.rs 75.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #273      +/-   ##
==========================================
+ Coverage   90.28%   90.29%   +0.01%     
==========================================
  Files          80       80              
  Lines        7390     7390              
==========================================
+ Hits         6672     6673       +1     
+ Misses        718      717       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@wolf4ood wolf4ood left a comment

Choose a reason for hiding this comment

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

LGTM 🚀

@Gsantomaggio
Copy link
Member

Can we merge @DanielePalaia ?

@Gsantomaggio Gsantomaggio merged commit be36db2 into rabbitmq:main Feb 18, 2025
2 of 3 checks passed
@Gsantomaggio
Copy link
Member

Thanks a lot @allevo and @wolf4ood

@github-actions github-actions bot mentioned this pull request Feb 18, 2025
@github-actions github-actions bot mentioned this pull request Apr 18, 2025
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