-
Notifications
You must be signed in to change notification settings - Fork 84
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
refactor(metrics/histogram): 🎂 constructor accepts IntoIterator
#243
base: master
Are you sure you want to change the base?
Conversation
IntoIterator
IntoIterator
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me. Neat!
@cratelyn would you mind adding a changelog entry?
this is a very small, **non-breaking**, alteration to the signature of `Histogram`'s constructor. rather than accepting an `impl Iterator`, this commit changes the parameter of `Histogram::new()` to be an `impl IntoIterator` instead. this does not affect the existing contract because of the blanket `impl<I: Iterator> IntoIterator for I` implementation provided by the standard library. by accepting `IntoIterator` however, callers providing a collection such as a `[f64; 5]` array or a `Vec<f64>` vector do not need to invoke `into_iter()` themselves at the call-site. ```rust // now, constructing a histogram needn't involve `into_iter()`... use prometheus_client::metrics::histogram::Histogram; let histogram = Histogram::new([10.0, 100.0, 1_000.0]); ``` this leans on the same sugar used by `for {}` loops, see the relevant section of the `std::iter` documentation here: <https://doc.rust-lang.org/stable/std/iter/index.html#for-loops-and-intoiterator> no changes are needed within `Histogram::new()` because we already call `into_iter()` on the provider iterator when appending `f64::MAX` and collecting the buckets into a `Vec<_>`. Signed-off-by: katelyn martin <me+cratelyn@katelyn.world>
9993c64
to
1e216f1
Compare
sure thing! i've rebased this on the latest |
@@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file. | |||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), | |||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | |||
|
|||
## [0.24.0] - unreleased |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
## [0.24.0] - unreleased | |
## [0.23.1] |
Not a breaking change.
Also, if you bump the version in Cargo.toml
to v0.24.1
I am happy to cut a patch release right away.
@@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file. | |||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), | |||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | |||
|
|||
## [0.24.0] - unreleased | |||
|
|||
- `Histogram::new` now accepts an `IntoIterator` argument, rather than an `Iterator`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- `Histogram::new` now accepts an `IntoIterator` argument, rather than an `Iterator`. | |
### Added | |
- `Histogram::new` now accepts an `IntoIterator` argument, rather than an `Iterator`. |
See keepachangelog format.
this is a very small, non-breaking, alteration to the signature of
Histogram
's constructor.rather than accepting an
impl Iterator
, this commit changes the parameter ofHistogram::new()
to be animpl IntoIterator
instead. this does not affect the existing contract because of the blanketimpl<I: Iterator> IntoIterator for I
implementation provided by the standard library.by accepting
IntoIterator
however, callers providing a collection such as a[f64; 5]
array or aVec<f64>
vector do not need to invokeinto_iter()
themselves at the call-site.this leans on the same sugar used by
for {}
loops, see the relevant section of thestd::iter
documentation here:https://doc.rust-lang.org/stable/std/iter/index.html#for-loops-and-intoiterator
no changes are needed within
Histogram::new()
because we already callinto_iter()
on the provider iterator when appendingf64::MAX
and collecting the buckets into aVec<_>
.