1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//! Multiline re-indentation for layout-owning strategies.
//!
//! Foreign content (error messages, custom strategies) may embed `\n`. A
//! strategy that owns a 2-D layout ([`Tree`](crate::Tree),
//! [`List`](crate::List), [`Bullets`](crate::Bullets), [`Chain`](crate::Chain))
//! writes such content through [`indented`] so every physical line stays under
//! the strategy's own column instead of spilling flush-left. Streams
//! line-by-line — no allocation, available without `alloc`.
//!
//! These are the same primitives the built-in shapes use; they are public so a
//! custom [`Format`](crate::Format) strategy can re-indent its own foreign
//! content identically.
//!
//! # Design note
//!
//! The `Indented` adapter below is a hand-rolled slice of two well-known
//! things: std's own
//! internal `core::fmt::builders::PadAdapter` (which indents nested `{:#?}`),
//! and the `nest`/`line` of a Wadler-style pretty-printer. The *concept* —
//! re-emit a continuation prefix after each newline — is forced by the goal
//! (stream foreign content into a 2-D layout) and survives any redesign. The
//! *encoding* is contingent: a `Doc` algebra or a scoped prefix-stack writer
//! could absorb [`indented`] and [`Repeat`] (and `Tree`'s `Pad`) into one
//! mechanism, but that relocates the complexity (allocation, a `Doc` to
//! maintain) rather than removing it. [`Repeat`] (uniform unit × N, used by
//! `Chain`/`List`/`Bullets`) and `Tree`'s `Pad` (heterogeneous per-level bars
//! vs gaps) are two genuine prefix *shapes*, not redundancy.
use ;
/// A [`fmt::Write`] adapter that re-emits `prefix` after every newline, so
/// content spanning multiple physical lines keeps its column.
/// Writes `content` to `f`, re-indenting any embedded newlines to `prefix`.
/// [`Display`]-able repetition of a unit string — a reusable continuation
/// prefix for [`indented`] (unlike `itertools`' one-shot `format`, this can be
/// formatted once per embedded newline).
///
/// `Repeat(unit, n)` renders `unit` written `n` times.
;