mgeisler / textwrap

An efficient and powerful Rust library for word wrapping text.
MIT License
446 stars 44 forks source link

Add `wrap`, `fill`, `refill` methods to `Options` #523

Closed 9999years closed 10 months ago

9999years commented 11 months ago

These functions all take an Options as a parameter. I usually construct an Options and then use it for multiple calls, so it's more convenient for me to have access to these as methods.

mgeisler commented 10 months ago

Hi @9999years, thanks for the PR.

This change would make the API similar to what I had before version 0.13 from 2020. So I can fully understand why this API seems natural — I started out with the same one :smile:

My feeling back then is summed up a bit in #213, but overall I was concerned about two things:

Since 2020, the library has also gotten some simple column wrapping functionality — but you didn't add those rarely-used methods to the Options struct here :smile: I would prefer not having to decide that is important enough to be added as methods to Options.

Does this seem reasonable?

9999years commented 10 months ago

Hmm. If we're talking about breaking changes in #521 already, here's my proposal:

mgeisler commented 10 months ago
  • Top-level formatting functions with default options (textwrap::wrap("foo"), textwrap::fill("foo"), etc.)

I don't think this will work: we need to know the correct wrapping width at the very least. The library could of course make an "opinionated" guess by using 80 columns or so, but I feel that won't be very popular with most people.

I will not add back the methods that were removed back in 2020 because of the problems I mentioned above. Overall, I hope the API of the crate can:

I feel the current API does this pretty well. Having to import both Options and wrap or fill seems okay to me.