Skip to content

Commit

Permalink
Configure required features for examples
Browse files Browse the repository at this point in the history
Instead of manually checking for required features in the hyphenation
and termwidth examples, we can configure the required features in
Cargo.toml.  This makes the examples easier to read and maintain.
  • Loading branch information
robinkrahl committed Jul 1, 2021
1 parent 7cec76d commit 694412c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 18 deletions.
8 changes: 8 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ license = "MIT"
edition = "2018"
exclude = [".github/", ".gitignore", "benches/", "examples/", "fuzz/", "images/"]

[[example]]
name = "hyphenation"
required-features = ["hyphenation"]

[[example]]
name = "termwidth"
required-features = ["terminal_size"]

[package.metadata.docs.rs]
all-features = true

Expand Down
11 changes: 0 additions & 11 deletions examples/hyphenation.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
#[cfg(feature = "hyphenation")]
use hyphenation::{Language, Load, Standard};

#[cfg(not(feature = "hyphenation"))]
fn main() {
println!("Please run this example as");
println!();
println!(" cargo run --example hyphenation --features hyphenation");
}

#[cfg(feature = "hyphenation")]
fn main() {
let text = "textwrap: a small library for wrapping text.";
let dictionary = Standard::from_embedded(Language::EnglishUS).unwrap();
Expand Down
7 changes: 0 additions & 7 deletions examples/termwidth.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
#[cfg(feature = "terminal_size")]
use textwrap::{fill, Options};

#[cfg(not(feature = "terminal_size"))]
fn main() {
println!("Please enable the terminal_size Cargo feature to run this example.");
}

#[cfg(feature = "terminal_size")]
fn main() {
let example = "Memory safety without garbage collection. \
Concurrency without data races. \
Expand Down

0 comments on commit 694412c

Please sign in to comment.