Skip to content

Commit b7e8745

Browse files
authored
Let the cargo.toml know which example requires which features (#511)
Signed-off-by: Tamo <[email protected]>
1 parent f49c724 commit b7e8745

File tree

3 files changed

+8
-20
lines changed

3 files changed

+8
-20
lines changed

Cargo.toml

+8
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,11 @@ harness = false
7070
[[bench]]
7171
name = "text_encoder"
7272
harness = false
73+
74+
[[example]]
75+
name = "example_push"
76+
required-features = ["push"]
77+
78+
[[example]]
79+
name = "example_process_collector"
80+
required-features = ["process"]

examples/example_process_collector.rs

-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// Copyright 2019 TiKV Project Authors. Licensed under Apache-2.0.
22

3-
#[cfg(all(feature = "process", target_os = "linux"))]
43
fn main() {
54
use std::thread;
65
use std::time::Duration;
@@ -21,11 +20,3 @@ fn main() {
2120
thread::sleep(Duration::from_secs(1));
2221
}
2322
}
24-
25-
#[cfg(any(not(feature = "process"), not(target_os = "linux")))]
26-
fn main() {
27-
println!(
28-
r#"Please enable feature "process", try:
29-
cargo run --features="process" --example example_process_collector"#
30-
);
31-
}

examples/example_push.rs

-11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
// Copyright 2019 TiKV Project Authors. Licensed under Apache-2.0.
22

3-
#![cfg_attr(not(feature = "push"), allow(unused_imports, dead_code))]
4-
53
use std::env;
64
use std::thread;
75
use std::time;
@@ -25,7 +23,6 @@ lazy_static! {
2523
.unwrap();
2624
}
2725

28-
#[cfg(feature = "push")]
2926
fn main() {
3027
let args: Vec<String> = env::args().collect();
3128
let program = args[0].clone();
@@ -68,11 +65,3 @@ fn main() {
6865

6966
println!("Okay, please check the Pushgateway.");
7067
}
71-
72-
#[cfg(not(feature = "push"))]
73-
fn main() {
74-
println!(
75-
r#"Please enable feature "push", try:
76-
cargo run --features="push" --example example_push"#
77-
);
78-
}

0 commit comments

Comments
 (0)