[][src]Function textwrap::wrap_iter

pub fn wrap_iter(s: &str, width: usize) -> IntoWrapIter<HyphenSplitter>

Lazily wrap a line of text at width characters.

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.

Examples

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

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

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