indent-string
Indent each line of a multi-line string.
foo\nbar → foo\n bar. A faithful Rust port of the widely-used
indent-string npm package. The counterpart
of strip-indent.
- Zero dependencies,
#![no_std] - Repeat count, custom indent string, and an
include_empty_linesoption - Differential-tested against the reference
indent-stringimplementation
Install
[]
= "0.1"
Usage
use ;
assert_eq!;
// Repeat count + custom indent:
assert_eq!;
// By default, empty / whitespace-only lines are not indented:
assert_eq!;
// ...unless you opt in:
assert_eq!;
A count of 0 returns the string unchanged. Indentation is applied after every JavaScript
line terminator (\n, \r, \u{2028}, \u{2029}), matching the reference's /^/gm.
Contributors ✨
This project follows the all-contributors specification. Contributions of any kind are welcome — code, docs, bug reports, ideas, reviews! See the emoji key for how each contribution is recognized, and open a PR or issue to get involved.
Thanks goes to these wonderful people:
License
Licensed under either of MIT or Apache-2.0 at your option.