]>
Commit | Line | Data |
---|---|---|
041b39d2 XL |
1 | #[cfg(feature = "hyphenation")] |
2 | extern crate hyphenation; | |
3 | extern crate textwrap; | |
4 | ||
5 | #[cfg(feature = "hyphenation")] | |
6 | use hyphenation::Language; | |
7 | use textwrap::Wrapper; | |
8 | ||
9 | ||
10 | #[cfg(not(feature = "hyphenation"))] | |
ea8adc8c | 11 | fn new_wrapper<'a>() -> Wrapper<'a, textwrap::HyphenSplitter> { |
041b39d2 XL |
12 | Wrapper::new(0) |
13 | } | |
14 | ||
15 | #[cfg(feature = "hyphenation")] | |
ea8adc8c | 16 | fn new_wrapper<'a>() -> Wrapper<'a, hyphenation::Corpus> { |
041b39d2 | 17 | let corpus = hyphenation::load(Language::English_US).unwrap(); |
ea8adc8c | 18 | Wrapper::with_splitter(0, corpus) |
041b39d2 XL |
19 | } |
20 | ||
21 | fn main() { | |
3b2f2976 XL |
22 | let example = "Memory safety without garbage collection. \ |
23 | Concurrency without data races. \ | |
24 | Zero-cost abstractions."; | |
041b39d2 XL |
25 | let mut prev_lines = vec![]; |
26 | let mut wrapper = new_wrapper(); | |
27 | for width in 15..60 { | |
28 | wrapper.width = width; | |
29 | let lines = wrapper.wrap(example); | |
30 | if lines != prev_lines { | |
31 | let title = format!(" Width: {} ", width); | |
32 | println!(".{:-^1$}.", title, width + 2); | |
33 | for line in &lines { | |
34 | println!("| {:1$} |", line, width); | |
35 | } | |
36 | prev_lines = lines; | |
37 | } | |
38 | } | |
39 | } |