Skip to content

Commit 1e7736f

Browse files
authored
Clean up the use of macro_use and extern crate (#398)
* Clean up the use of macro_use and extern crate Signed-off-by: JmPotato <[email protected]> * Fix the build Signed-off-by: JmPotato <[email protected]>
1 parent de89aae commit 1e7736f

29 files changed

+82
-118
lines changed

examples/example_custom_registry.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@
33
//! This examples shows how to use multiple and custom registries,
44
//! and how to perform registration across function boundaries.
55
6-
#[macro_use]
7-
extern crate lazy_static;
8-
extern crate prometheus;
9-
106
use std::collections::HashMap;
117

128
use prometheus::{Encoder, IntCounter, Registry};
139

10+
use lazy_static::lazy_static;
11+
1412
lazy_static! {
1513
static ref DEFAULT_COUNTER: IntCounter = IntCounter::new("default", "generic counter").unwrap();
1614
static ref CUSTOM_COUNTER: IntCounter = IntCounter::new("custom", "dedicated counter").unwrap();

examples/example_hyper.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
// Copyright 2019 TiKV Project Authors. Licensed under Apache-2.0.
22

3-
#[macro_use]
4-
extern crate lazy_static;
5-
#[macro_use]
6-
extern crate prometheus;
7-
83
use hyper::{
94
header::CONTENT_TYPE,
105
service::{make_service_fn, service_fn},
116
Body, Request, Response, Server,
127
};
138
use prometheus::{Counter, Encoder, Gauge, HistogramVec, TextEncoder};
149

10+
use lazy_static::lazy_static;
11+
use prometheus::{labels, opts, register_counter, register_gauge, register_histogram_vec};
12+
1513
lazy_static! {
1614
static ref HTTP_COUNTER: Counter = register_counter!(opts!(
1715
"example_http_requests_total",

examples/example_int_metrics.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// Copyright 2019 TiKV Project Authors. Licensed under Apache-2.0.
22

3-
#[macro_use]
4-
extern crate lazy_static;
5-
#[macro_use]
6-
extern crate prometheus;
7-
83
use prometheus::{IntCounter, IntCounterVec, IntGauge, IntGaugeVec};
94

5+
use lazy_static::lazy_static;
6+
use prometheus::{
7+
register_int_counter, register_int_counter_vec, register_int_gauge, register_int_gauge_vec,
8+
};
9+
1010
lazy_static! {
1111
static ref A_INT_COUNTER: IntCounter =
1212
register_int_counter!("A_int_counter", "foobar").unwrap();

examples/example_push.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,16 @@
22

33
#![cfg_attr(not(feature = "push"), allow(unused_imports, dead_code))]
44

5-
#[macro_use]
6-
extern crate lazy_static;
7-
#[macro_use]
8-
extern crate prometheus;
9-
105
use std::env;
116
use std::thread;
127
use std::time;
138

149
use getopts::Options;
1510
use prometheus::{Counter, Histogram};
1611

12+
use lazy_static::lazy_static;
13+
use prometheus::{labels, register_counter, register_histogram};
14+
1715
lazy_static! {
1816
static ref PUSH_COUNTER: Counter = register_counter!(
1917
"example_push_total",

src/lib.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,11 @@ This crate supports staticly built metrics. You can use it with
5353
some metrics.
5454
5555
```rust
56-
#[macro_use] extern crate lazy_static;
57-
#[macro_use] extern crate prometheus;
5856
use prometheus::{self, IntCounter, TextEncoder, Encoder};
5957
58+
use lazy_static::lazy_static;
59+
use prometheus::register_int_counter;
60+
6061
lazy_static! {
6162
static ref HIGH_FIVE_COUNTER: IntCounter =
6263
register_int_counter!("highfives", "Number of high fives received").unwrap();
@@ -71,11 +72,12 @@ By default, this registers with a default registry. To make a report, you can ca
7172
[`Encoder`](trait.Encoder.html) and report to Promethus.
7273
7374
```
74-
# #[macro_use] extern crate lazy_static;
75-
#[macro_use] extern crate prometheus;
7675
# use prometheus::IntCounter;
7776
use prometheus::{self, TextEncoder, Encoder};
7877
78+
use lazy_static::lazy_static;
79+
use prometheus::register_int_counter;
80+
7981
// Register & measure some metrics.
8082
# lazy_static! {
8183
# static ref HIGH_FIVE_COUNTER: IntCounter =
@@ -145,11 +147,6 @@ macro_rules! from_vec {
145147
};
146148
}
147149

148-
#[macro_use]
149-
extern crate cfg_if;
150-
#[macro_use]
151-
extern crate lazy_static;
152-
153150
#[macro_use]
154151
mod macros;
155152
mod atomic64;

src/macros.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
/// # Examples
66
///
77
/// ```
8-
/// # #[macro_use] extern crate prometheus;
98
/// # use std::collections::HashMap;
9+
/// # use prometheus::labels;
1010
/// # fn main() {
1111
/// let labels = labels!{
1212
/// "test" => "hello",
@@ -41,7 +41,7 @@ macro_rules! labels {
4141
/// # Examples
4242
///
4343
/// ```
44-
/// # #[macro_use] extern crate prometheus;
44+
/// # use prometheus::{labels, opts};
4545
/// # fn main() {
4646
/// let name = "test_opts";
4747
/// let help = "test opts help";
@@ -87,8 +87,8 @@ macro_rules! opts {
8787
/// # Examples
8888
///
8989
/// ```
90-
/// # #[macro_use] extern crate prometheus;
9190
/// # use prometheus::linear_buckets;
91+
/// # use prometheus::{histogram_opts, labels};
9292
/// # fn main() {
9393
/// let name = "test_histogram_opts";
9494
/// let help = "test opts help";
@@ -135,7 +135,7 @@ macro_rules! histogram_opts {
135135
/// # Examples
136136
///
137137
/// ```
138-
/// # #[macro_use] extern crate prometheus;
138+
/// # use prometheus::{opts, register_counter};
139139
/// # fn main() {
140140
/// let opts = opts!("test_macro_counter_1", "help");
141141
/// let res1 = register_counter!(opts);
@@ -189,7 +189,7 @@ macro_rules! __register_counter_vec {
189189
/// # Examples
190190
///
191191
/// ```
192-
/// # #[macro_use] extern crate prometheus;
192+
/// # use prometheus::{opts, register_counter_vec};
193193
/// # fn main() {
194194
/// let opts = opts!("test_macro_counter_vec_1", "help");
195195
/// let counter_vec = register_counter_vec!(opts, &["a", "b"]);
@@ -238,7 +238,7 @@ macro_rules! __register_gauge {
238238
/// # Examples
239239
///
240240
/// ```
241-
/// # #[macro_use] extern crate prometheus;
241+
/// # use prometheus::{opts, register_gauge};
242242
/// # fn main() {
243243
/// let opts = opts!("test_macro_gauge", "help");
244244
/// let res1 = register_gauge!(opts);
@@ -287,7 +287,7 @@ macro_rules! __register_gauge_vec {
287287
/// # Examples
288288
///
289289
/// ```
290-
/// # #[macro_use] extern crate prometheus;
290+
/// # use prometheus::{opts, register_gauge_vec};
291291
/// # fn main() {
292292
/// let opts = opts!("test_macro_gauge_vec_1", "help");
293293
/// let gauge_vec = register_gauge_vec!(opts, &["a", "b"]);
@@ -327,7 +327,7 @@ macro_rules! register_int_gauge_vec {
327327
/// # Examples
328328
///
329329
/// ```
330-
/// # #[macro_use] extern crate prometheus;
330+
/// # use prometheus::{histogram_opts, register_histogram};
331331
/// # fn main() {
332332
/// let opts = histogram_opts!("test_macro_histogram", "help");
333333
/// let res1 = register_histogram!(opts);
@@ -363,7 +363,7 @@ macro_rules! register_histogram {
363363
/// # Examples
364364
///
365365
/// ```
366-
/// # #[macro_use] extern crate prometheus;
366+
/// # use prometheus::{histogram_opts, register_histogram_vec};
367367
/// # fn main() {
368368
/// let opts = histogram_opts!("test_macro_histogram_vec_1", "help");
369369
/// let histogram_vec = register_histogram_vec!(opts, &["a", "b"]);

src/process_collector.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
77
use std::sync::Mutex;
88

9+
use lazy_static::lazy_static;
10+
911
use crate::counter::Counter;
1012
use crate::desc::Desc;
1113
use crate::gauge::Gauge;

src/push.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ use reqwest::blocking::Client;
1010
use reqwest::header::CONTENT_TYPE;
1111
use reqwest::{Method, StatusCode, Url};
1212

13+
use lazy_static::lazy_static;
14+
1315
use crate::encoder::{Encoder, ProtobufEncoder};
1416
use crate::errors::{Error, Result};
1517
use crate::metrics::Collector;

src/registry.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ use crate::errors::{Error, Result};
1212
use crate::metrics::Collector;
1313
use crate::proto;
1414

15+
use cfg_if::cfg_if;
16+
use lazy_static::lazy_static;
17+
1518
struct RegistryCore {
1619
pub collectors_by_id: HashMap<u64, Box<dyn Collector>>,
1720
pub dim_hashes_by_name: HashMap<String, u64>,

src/timer.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ use std::sync::atomic::{AtomicBool, AtomicU64, Ordering};
22
use std::thread;
33
use std::time::{Duration, Instant};
44

5+
use lazy_static::lazy_static;
6+
57
/// Milliseconds since ANCHOR.
68
static RECENT: AtomicU64 = AtomicU64::new(0);
79
lazy_static! {

0 commit comments

Comments
 (0)