Skip to content

Commit

Permalink
Turn top-level examples into executable tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mgeisler committed Jul 10, 2021
1 parent 3f3ae37 commit 0a2aea6
Showing 1 changed file with 17 additions and 32 deletions.
49 changes: 17 additions & 32 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,47 +7,32 @@
//! you want to format dynamic output nicely so it looks good in a
//! terminal. A quick example:
//!
//! ```no_run
//! fn main() {
//! let text = "textwrap: a small library for wrapping text.";
//! println!("{}", textwrap::fill(text, 18));
//! }
//! ```
//!
//! When you run this program, it will display the following output:
//!
//! ```text
//! textwrap: a small
//! library for
//! wrapping text.
//! let text = "textwrap: a small library for wrapping text.";
//! assert_eq!(textwrap::wrap(text, 18),
//! vec!["textwrap: a",
//! "small library for",
//! "wrapping text."]);
//! ```
//!
//! The [`wrap`] function returns the individual lines, use [`fill`]
//! is you want the lines joined to a `String`.
//!
//! If you enable the `hyphenation` Cargo feature, you can get
//! automatic hyphenation for a number of languages:
//!
//! ```no_run
//! # #[cfg(feature = "hyphenation")]
//! ```
//! #[cfg(feature = "hyphenation")] {
//! use hyphenation::{Language, Load, Standard};
//! use textwrap::{fill, Options};
//!
//! # #[cfg(feature = "hyphenation")]
//! fn main() {
//! let text = "textwrap: a small library for wrapping text.";
//! let dictionary = Standard::from_embedded(Language::EnglishUS).unwrap();
//! let options = Options::new(18).word_splitter(dictionary);
//! println!("{}", fill(text, &options));
//! let text = "textwrap: a small library for wrapping text.";
//! let dictionary = Standard::from_embedded(Language::EnglishUS).unwrap();
//! let options = textwrap::Options::new(18).word_splitter(dictionary);
//! assert_eq!(textwrap::wrap(text, &options),
//! vec!["textwrap: a small",
//! "library for wrap-",
//! "ping text."]);
//! }
//!
//! # #[cfg(not(feature = "hyphenation"))]
//! # fn main() { }
//! ```
//!
//! The program will now output:
//!
//! ```text
//! textwrap: a small
//! library for wrap-
//! ping text.
//! ```
//!
//! See also the [`unfill`] and [`refill`] functions which allow you to
Expand Down

0 comments on commit 0a2aea6

Please sign in to comment.