cloud-hypervisor/vendor/registry-40351f815f426200/textwrap/examples/layout.rs
Samuel Ortiz d5f5648b37 vendor: Add vendored dependencies
We use cargo vendor to generate a .cargo/config file and the vendor
directory. Vendoring allows us to lock our dependencies and to modify
them easily from the top level Cargo.toml.

We vendor all dependencies, including the crates.io ones, which allows
for network isolated builds.

Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2019-06-04 17:51:52 +02:00

40 lines
1.1 KiB
Rust

#[cfg(feature = "hyphenation")]
extern crate hyphenation;
extern crate textwrap;
#[cfg(feature = "hyphenation")]
use hyphenation::Language;
use textwrap::Wrapper;
#[cfg(not(feature = "hyphenation"))]
fn new_wrapper<'a>() -> Wrapper<'a, textwrap::HyphenSplitter> {
Wrapper::new(0)
}
#[cfg(feature = "hyphenation")]
fn new_wrapper<'a>() -> Wrapper<'a, hyphenation::Corpus> {
let corpus = hyphenation::load(Language::English_US).unwrap();
Wrapper::with_splitter(0, corpus)
}
fn main() {
let example = "Memory safety without garbage collection. \
Concurrency without data races. \
Zero-cost abstractions.";
let mut prev_lines = vec![];
let mut wrapper = new_wrapper();
for width in 15..60 {
wrapper.width = width;
let lines = wrapper.wrap(example);
if lines != prev_lines {
let title = format!(" Width: {} ", width);
println!(".{:-^1$}.", title, width + 2);
for line in &lines {
println!("| {:1$} |", line, width);
}
prev_lines = lines;
}
}
}