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
Replace lazy static initializers with const fn #221
Comments
I peeked at the details of this task briefly and it does not look so simple; certainly not as simple as converting (in the above example) @Hoverbear @overvenus do you have an idea of the transformation that needs to be done here? |
In this case @breeswish would be a good resource |
@brson I tried with |
This is problematic. :( |
A Not using the macro means user would write instead static TIKV_REQUEST_DURATION_HISTOGRAM_VEC: HistogramVec = HistogramVec::new(
"tikv_request_duration_seconds",
"Bucketed histogram of TiKV requests duration",
&["type"],
);
static SOME_MORE_COLLECTORS: ... = ...;
fn main() -> Result<()> {
register(Box::new(TIKV_REQUEST_DURATION_HISTOGRAM_VEC.clone())?;
register(Box::new(SOME_MORE_COLLECTORS.clone())?; // <-- need to call these manually :(
...
} |
Thanks @kennytm ! I think we can wait rust-lang/rust#57563 and then mark as more function as possible to be Additionally, I would like to mention that the process of registering and creating a metric can be simplified, for example, in 1.0-pre, we can just write: let counter = CounterBuilder::new("name", "help")
.build_vec(["a", "b"])
.unwrap(); |
A cleaner alternative is https://docs.rs/once_cell/1.4.0/once_cell/#lazy-initialized-global-data |
Should be possible after upgrading to 2018 re #217 (comment)
The text was updated successfully, but these errors were encountered: