Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify API with only top-level functions #213

Merged
merged 3 commits into from
Sep 30, 2020
Merged

Simplify API with only top-level functions #213

merged 3 commits into from
Sep 30, 2020

Conversation

mgeisler
Copy link
Owner

@mgeisler mgeisler commented Sep 26, 2020

This is a breaking change which simplifies and stream-lines the API in several ways:

  • Instead of having both Wrapper::wrap and a top-level textwrap::wrap function, we now only have the textwrap::wrap
    function. This should simplify things a little since there is now just one way to use the API.

  • The Wrapper struct has been turned into an Options struct.

  • The API of textwrap::wrap and textwrap::fill functions have changed in a backwards compatible fashion. They still take a string and a width:

    textwrap::fill("some string", 10);
    
  • In addition to a usize width, you can now also pass Options as the second argument:

    textwrap::fill("some string", Options::new(10).break_words(false));
    

Migration from using Wrapper is simple: change a call to Wrapper::fill to fill:

use textwrap::Wrapper;
let wrapper = Wrapper::new(10).initial_indent("  ");
wrapper.fill("some string")

into

use textwrap::{Options, fill};
let options = Options::new(10).initial_indent("  ");
fill("some string", &options)

@mgeisler mgeisler force-pushed the simplify-api branch 7 times, most recently from dfb7b46 to e845691 Compare September 30, 2020 04:03
The wrap and wrap_iter functions both return lines of wrapped text.
The difference is that wrap_iter return an iterator, whereas wrap
collects the lines into a vector.
It was only used from textwrap::wrap and removing it makes our API
leaner without losing expressive power.
This is a breaking change which simplifies and streamlines the API in
several ways:

* Instead of having both Wrapper::wrap and a top-level wrap function,
we now only have the wrap function. This should simplify things a
little since there is now just one way to use the API.

* The Wrapper struct has been turned into an Options struct, which
  carries all the configuration settings.

* The API of the wrap and fill functions have changed in a backwards
  compatible fashion. They still take a string and a width:

        textwrap::fill("some string", 10);

* In addition to an usize width, you can now also pass Options as the
  second argument:

        textwrap::fill("some string", Options::new(10).break_words(false));
@mgeisler mgeisler changed the title Simplify API Simplify API with only top-level functions Sep 30, 2020
@mgeisler mgeisler merged commit d81f434 into master Sep 30, 2020
mgeisler added a commit that referenced this pull request Oct 13, 2020
The first part of the documentation was lost by accident in #213.
mgeisler added a commit that referenced this pull request Nov 8, 2020
The function existed briefly while I was developing #213, but it was
removed before the PR was merged.
@mgeisler mgeisler deleted the simplify-api branch January 30, 2021 16:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant