Skip to content

Commit

Permalink
Merge pull request #215 from Cryptjar/master
Browse files Browse the repository at this point in the history
Reintroducing the type parameter on `Options` (previously known as `Wrapper`).
  • Loading branch information
mgeisler authored Nov 9, 2020
2 parents 52c39c3 + 7892add commit 11caddb
Show file tree
Hide file tree
Showing 8 changed files with 288 additions and 47 deletions.
11 changes: 8 additions & 3 deletions benches/linear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,16 @@ pub fn benchmark(c: &mut Criterion) {
let mut group = c.benchmark_group("String lengths");
for length in [100, 200, 400, 800, 1600].iter() {
let text = lorem_ipsum(*length);
let mut options = textwrap::Options::new(LINE_LENGTH);
let options = textwrap::Options::new(LINE_LENGTH);
group.bench_with_input(BenchmarkId::new("fill", length), &text, |b, text| {
b.iter(|| textwrap::fill(text, &options));
});

let options: textwrap::Options = options.splitter(Box::new(textwrap::HyphenSplitter));
group.bench_with_input(BenchmarkId::new("fill_boxed", length), &text, |b, text| {
b.iter(|| textwrap::fill(text, &options));
});

group.bench_with_input(BenchmarkId::new("fill_usize", length), &text, |b, text| {
b.iter(|| textwrap::fill(text, LINE_LENGTH));
});
Expand All @@ -39,11 +44,11 @@ pub fn benchmark(c: &mut Criterion) {
.join("benches")
.join("la.standard.bincode");
let dictionary = Standard::from_path(Language::Latin, &path).unwrap();
options.splitter = Box::new(dictionary);
let options = options.splitter(dictionary);
group.bench_with_input(BenchmarkId::new("hyphenation", length), &text, |b, text| {
b.iter(|| textwrap::fill(text, &options));
});
}
};
}
group.finish();
}
Expand Down
2 changes: 1 addition & 1 deletion examples/hyphenation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ fn main() {
fn main() {
let text = "textwrap: a small library for wrapping text.";
let dictionary = Standard::from_embedded(Language::EnglishUS).unwrap();
let options = textwrap::Options::new(18).splitter(Box::new(dictionary));
let options = textwrap::Options::new(18).splitter(dictionary);
println!("{}", textwrap::fill(text, &options));
}
4 changes: 2 additions & 2 deletions examples/interactive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ mod unix_only {
}

let mut label = labels.pop().unwrap();
let mut options = Options::new(initial_width);
let mut options: Options = Options::new(initial_width).splitter(Box::new(HyphenSplitter));
options.break_words = false;
options.splitter = splitters.pop().unwrap();

Expand Down Expand Up @@ -203,7 +203,7 @@ mod unix_only {

// TODO: change to cursor::DefaultStyle if
// https://github.com/redox-os/termion/pull/157 is merged.
screen.write(b"\x1b[0 q")?;
screen.write_all(b"\x1b[0 q")?;
screen.flush()
}
}
4 changes: 2 additions & 2 deletions examples/layout.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use textwrap::{wrap, Options};
use textwrap::{wrap, HyphenSplitter, Options};

fn main() {
let example = "Memory safety without garbage collection. \
Concurrency without data races. \
Zero-cost abstractions.";
let mut prev_lines = vec![];

let mut options = Options::new(0);
let mut options: Options = Options::new(0).splitter(Box::new(HyphenSplitter));
#[cfg(feature = "hyphenation")]
{
use hyphenation::Load;
Expand Down
4 changes: 2 additions & 2 deletions examples/termwidth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ fn main() {
#[cfg(feature = "hyphenation")]
let (msg, options) = (
"with hyphenation",
Options::with_termwidth().splitter(Box::new(
Options::with_termwidth().splitter(
hyphenation::Standard::from_embedded(hyphenation::Language::EnglishUS).unwrap(),
)),
),
);

println!("Formatted {} in {} columns:", msg, options.width);
Expand Down
4 changes: 2 additions & 2 deletions src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ pub fn find_words(line: &str) -> impl Iterator<Item = Word> {
/// );
///
/// // The NoHyphenation splitter ignores the '-':
/// let options = Options::new(80).splitter(Box::new(NoHyphenation));
/// let options = Options::new(80).splitter(NoHyphenation);
/// assert_eq!(
/// split_words(vec![Word::from("foo-bar")], &&options).collect::<Vec<_>>(),
/// vec![Word::from("foo-bar")]
Expand Down Expand Up @@ -548,7 +548,7 @@ mod tests {
}
}

let options = Options::new(80).splitter(Box::new(FixedSplitPoint));
let options = Options::new(80).splitter(FixedSplitPoint);
assert_iter_eq!(
split_words(vec![Word::from("foobar")].into_iter(), &&options),
vec![
Expand Down
Loading

0 comments on commit 11caddb

Please sign in to comment.