mgeisler / textwrap

An efficient and powerful Rust library for word wrapping text.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Make type used for line width computations generic

mgeisler opened this issue · comments

We currently use usize for line widths, which works well for terminal text. To support wrapping text for PDFs or SVGs, we need to be more flexible. We might be able to use f64, but we should probably make the type generic so that people can plug in their own bignum types.

This would also allow terminal text applications to use a smaller type, such as u16, which would lower the memory usage a 64-bit system.

With the changes in #421, we now use f64 internally in wrap_first_fit and wrap_optimal_fit. The top-level interface is still usize, but this is just because Textwrap is providing functions for wrapping console text (which is naturally measured in an integer number of columns).

I think this is a good compromise: the f64 type covers all integers up to about 2^53, so this covers our terminal use cases. Simultaneously, f64 makes it easy for GUI programs to wrap text measured in pt or px with sub-pixel accuracy.

This means that this issue is obsolete now.