Function textwrap::wrap_iter

source ·
pub fn wrap_iter(s: &str, width: usize) -> IntoWrapIter<'_, HyphenSplitter> 
Expand description

Lazily wrap a line of text at width characters. Strings are wrapped based on their displayed width, not their size in bytes.

This function creates a Wrapper on the fly with default settings. It then calls the into_wrap_iter method. Hence, the return value is an IntoWrapIter, not a WrapIter as the function name would otherwise suggest.

If you need to set a language corpus for automatic hyphenation, or need to wrap many strings, then it is suggested to create a Wrapper and call its wrap_iter or into_wrap_iter methods.


use std::borrow::Cow;
use textwrap::wrap_iter;

let mut wrap20_iter = wrap_iter("Zero-cost abstractions.", 20);
assert_eq!(, Some(Cow::from("Zero-cost")));
assert_eq!(, Some(Cow::from("abstractions.")));
assert_eq!(, None);

let mut wrap25_iter = wrap_iter("Zero-cost abstractions.", 25);
assert_eq!(, Some(Cow::from("Zero-cost abstractions.")));
assert_eq!(, None);