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

Consider adding #[must_use] to MetricBuilder #63

Closed
robinst opened this issue Mar 14, 2018 · 4 comments
Closed

Consider adding #[must_use] to MetricBuilder #63

robinst opened this issue Mar 14, 2018 · 4 comments
Milestone

Comments

@robinst
Copy link
Contributor

robinst commented Mar 14, 2018

I just updated my code to make use of tags (thanks for adding it, works great!). Now I have this code for example:

client.mark_with_tags("metric")
    .with_tag("key", "value")
    .send()
    .ok();

One thing that came up in the review was that it's easy to forget to call .send() on the MetricBuilder. And if you do, there's no warning.

So I was wondering, have you considered annotating MetricBuilder with #[must_use]? I gave it a quick try locally and it seems to work nicely, it results in a warning like this:

warning: unused cadence::builder::MetricBuilder which must be used

It prints that warning if you just have a mark_with_tags(...) and even when you have mark_with_tags(...).with_tag(...) (but forgot send).

@56quarters 56quarters added this to the 0.13.2 milestone Mar 14, 2018
@56quarters
Copy link
Owner

Great catch! I'll add this soon

@robinst
Copy link
Contributor Author

robinst commented Mar 14, 2018

That was quick :). Thanks!

While we have the example in the description, have you considered adding an alternative to the send method that ignores any errors instead of returning a result? Currently, not calling .ok() on the Result results in a warning.

@56quarters
Copy link
Owner

That method could be added. What do you think a good name would be? send_quiet()?

@56quarters
Copy link
Owner

I've opened #65 for the method that ignores the results and doesn't require calling .ok() on the result of .send()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants