|
3 | 3 | This file lists the most important changes made in each release of |
4 | 4 | `textwrap`. |
5 | 5 |
|
6 | | -## Unreleased |
| 6 | +## Version 0.14.0 (2021-06-05) |
7 | 7 |
|
8 | | -This is a major feature release which adds new generic type parameters |
9 | | -to the `Options` struct. These parameters lets you statically |
10 | | -configure the wrapping algorithm and the word separator: |
11 | | - |
12 | | -* `wrap_algorithms::WrapAlgorithm`: this trait replaces the old |
13 | | - `core::WrapAlgorithm` enum. The enum variants are now two structs: |
14 | | - `wrap_algorithms::FirstFit` and `wrap_algorithms::OptimalFit`. |
15 | | - |
16 | | -* `WordSeparator`: this new trait lets you specify how words are |
17 | | - separated in the text. Until now, Textwrap would simply split on |
18 | | - spaces. While this works okay for Western languages, it fails to |
19 | | - take emojis and East-Asian languages into account. |
20 | | - |
21 | | - The new `AsciiSpace` and `UnicodeBreakProperties` structs implement |
22 | | - the trait. The latter is available if the new optional |
23 | | - `unicode-linebreak` Cargo feature is enabled. |
| 8 | +This is a major feature release which makes Textwrap more configurable |
| 9 | +and flexible. The high-level API of `textwrap::wrap` and |
| 10 | +`textwrap::fill` remains unchanged, but low-level structs have moved |
| 11 | +around. |
24 | 12 |
|
25 | | -Common usages of textwrap stays unchanged, but if you previously |
26 | | -spelled out the full type for `Options`, you now need to take the |
27 | | -extra type parameters into account. This means that |
| 13 | +The biggest change is the introduction of new generic type parameters |
| 14 | +to the `Options` struct. These parameters lets you statically |
| 15 | +configure the wrapping algorithm, the word separator, and the word |
| 16 | +splitter. If you previously spelled out the full type for `Options`, |
| 17 | +you now need to take the extra type parameters into account. This |
| 18 | +means that |
28 | 19 |
|
29 | 20 | ```rust |
30 | 21 | let options: Options<HyphenSplitter> = Options::new(80); |
31 | 22 | ``` |
32 | 23 |
|
33 | | -need to change to |
| 24 | +changes to |
34 | 25 |
|
35 | 26 | ```rust |
36 | | -let options: Options<wrap_algorithms::FirstFit, AsciiSpace, HyphenSplitter> = Options::new(80); |
| 27 | +let options: Options< |
| 28 | + wrap_algorithms::FirstFit, |
| 29 | + word_separators::AsciiSpace, |
| 30 | + word_splitters::HyphenSplitter, |
| 31 | +> = Options::new(80); |
37 | 32 | ``` |
38 | 33 |
|
39 | | -You won’t see any chance if you call `wrap` directly with a width or |
40 | | -with an `Options` constructed on the fly. |
| 34 | +This is quite a mouthful, so we suggest using type inferrence where |
| 35 | +possible. You won’t see any chance if you call `wrap` directly with a |
| 36 | +width or with an `Options` value constructed on the fly. Please open |
| 37 | +an issue if this causes problems for you! |
| 38 | + |
| 39 | +### New `WordSeparator` Trait |
| 40 | + |
| 41 | +* [#332](https://github.com/mgeisler/textwrap/pull/332): Add |
| 42 | + `WordSeparator` trait to allow customizing how words are found in a |
| 43 | + line of text. Until now, Textwrap would always assume that words are |
| 44 | + separated by ASCII space characters. You can now customize this as |
| 45 | + needed. |
| 46 | + |
| 47 | +* [#313](https://github.com/mgeisler/textwrap/pull/313): Add support |
| 48 | + for using the Unicode line breaking algorithm to find words. This is |
| 49 | + done by adding a second implementation of the new `WordSeparator` |
| 50 | + trait. The implementation uses the unicode-linebreak crate, which is |
| 51 | + a new optional dependency. |
| 52 | + |
| 53 | + With this, Textwrap can be used with East-Asian languages such as |
| 54 | + Chinese or Japanese where there are no spaces between words. |
| 55 | + Breaking a long sequence of emojis is another example where line |
| 56 | + breaks might be wanted even if there are no whitespace to be found. |
| 57 | + Feedback would be appreciated for this feature. |
| 58 | + |
| 59 | + |
| 60 | +### Indent |
| 61 | + |
| 62 | +* [#353](https://github.com/mgeisler/textwrap/pull/353): Trim trailing |
| 63 | + whitespace from `prefix` in `indent`. |
| 64 | + |
| 65 | + Before, empty lines would get no prefix added. Now, empty lines have |
| 66 | + a trimmed prefix added. This little trick makes `indent` much more |
| 67 | + useful since you can now safely indent with `"# "` without creating |
| 68 | + trailing whitespace in the output due to the trailing whitespace in |
| 69 | + your prefix. |
| 70 | + |
| 71 | +* [#354](https://github.com/mgeisler/textwrap/pull/354): Make `indent` |
| 72 | + about 20% faster by preallocating the output string. |
| 73 | + |
| 74 | + |
| 75 | +### Documentation |
| 76 | + |
| 77 | +* [#308](https://github.com/mgeisler/textwrap/pull/308): Document |
| 78 | + handling of leading and trailing whitespace when wrapping text. |
| 79 | + |
| 80 | +### WebAssembly Demo |
| 81 | + |
| 82 | +* [#310](https://github.com/mgeisler/textwrap/pull/310): Thanks to |
| 83 | + WebAssembly, you can now try out Textwrap directly in your browser. |
| 84 | + Please try it out: https://mgeisler.github.io/textwrap/. |
| 85 | + |
| 86 | +### New Generic Parameters |
| 87 | + |
| 88 | +* [#331](https://github.com/mgeisler/textwrap/pull/331): Remove outer |
| 89 | + boxing from `Options`. |
| 90 | + |
| 91 | +* [#357](https://github.com/mgeisler/textwrap/pull/357): Replace |
| 92 | + `core::WrapAlgorithm` enum with a `wrap_algorithms::WrapAlgorithm` |
| 93 | + trait. This allows for arbitrary wrapping algorithms to be plugged |
| 94 | + into the library. |
| 95 | + |
| 96 | +* [#358](https://github.com/mgeisler/textwrap/pull/358): Switch |
| 97 | + wrapping functions to use a slice for `line_widths`. |
| 98 | + |
| 99 | +* [#368](https://github.com/mgeisler/textwrap/pull/368): Move |
| 100 | + `WordSeparator` and `WordSplitter` traits to separate modules. |
| 101 | + Before, Textwrap had several top-level structs such as |
| 102 | + `NoHyphenation` and `HyphenSplitter`. These implementations of |
| 103 | + `WordSplitter` now lives in a dedicated `word_splitters` module. |
| 104 | + Similarly, we have a new `word_separators` module for |
| 105 | + implementations of `WordSeparator`. |
| 106 | + |
| 107 | +* [#369](https://github.com/mgeisler/textwrap/pull/369): Rename |
| 108 | + `Options::splitter` to `Options::word_splitter` for consistency with |
| 109 | + the other fields backed by traits. |
41 | 110 |
|
42 | 111 | ## Version 0.13.4 (2021-02-23) |
43 | 112 |
|
|
0 commit comments