# 2.0 Validated Line Wrapping
Status: implemented in Commit 7 and public with body-specific names in the
`2.0.0` candidate.
Commit 7 replaces the representable-invalid 1.x wrapping shape with a 2.0
value whose line width is a `NonZeroUsize`. Commit 17 exposes that value as
`BodyWrap`, its line ending as `BodyLineEnding`, and its construction error as
`BodyWrapError`. These names describe Base64 body layout and do not claim a
complete MIME, PEM, or other protocol implementation.
## Construction And Representation
`LineWrap::try_new` is the only runtime constructor. It returns
`LineWrapError::ZeroWidth` for zero and otherwise stores the width as
`NonZeroUsize`. Both fields are private and immutable. Consequently:
- direct field construction and mutation are unavailable to callers;
- safe construction cannot create a zero-width, non-progressing encoder;
- there is no separate panicking `new` constructor;
- there is no redundant `checked_new` spelling; and
- there is no `is_valid` method because every constructed value is valid.
The value is `Copy`, `Send`, `Sync`, `no_std`, and allocation-free. Its error
implements `std::error::Error` only when the `std` feature is enabled. Checked
wrapped-length arithmetic returns `None` on overflow, including near
`usize::MAX`, and returns the exact encoded body size without a trailing line
ending.
## Trusted Body Layout Constants
The internal trusted constants are:
| `MIME_BODY_WRAP` | 76 | CRLF | MIME content-transfer body layout only |
| `PEM_BODY_LF_WRAP` | 64 | LF | PEM body layout only |
| `PEM_BODY_CRLF_WRAP` | 64 | CRLF | PEM body layout only |
These constants do not claim to parse MIME headers/messages or RFC 7468 PEM
boundaries, labels, and surrounding text. Commits 43 and 44 own those complete
protocol companions. Commit 17 combines body wrapping with explicitly
named codec specifications without broadening these constants' scope.
## Layout Semantics
Encoding inserts the configured line ending before each encoded byte that
would exceed the non-zero line width. It never appends a trailing line ending.
Validation requires every interior line to have exactly the configured width.
The final line may be shorter. For interoperability with body files, one final
configured line ending is accepted after a non-empty final line. Empty lines,
early interior endings, overlong lines, repeated endings, bare carriage
returns, bare line feeds under CRLF mode, and the wrong ending are rejected.
Validated compaction checks the complete layout and destination capacity
before writing, so malformed input and a small destination leave the caller's
output unchanged. Base64 alphabet, padding, and trailing-bit validation remain
the codec's responsibility; this value validates body layout only.
## Migration
The 1.x `LineWrap::new`, `LineWrap::checked_new`, public fields, and
`LineWrap::is_valid` remain available until the 2.0 API migration checkpoint.
Their 2.0 replacement is the public `BodyWrap` alias with one fallible
`try_new` constructor plus immutable accessors. Existing `LineWrap::MIME`,
`LineWrap::PEM`, and
`LineWrap::PEM_CRLF` users migrate to an explicitly named body or protocol
surface according to the API migration ledger.
## Evidence
`scripts/check-2.0-line-wrapping.sh` verifies:
- compile failure for external field construction;
- compile failure when a const policy attempts to accept zero width;
- exact trusted constant widths and endings;
- checked arithmetic at zero, one, and `usize::MAX` boundaries;
- exhaustive small width/length arithmetic against an independent formula;
- LF and CRLF insertion against the 1.x wrapped encoder;
- wrapped layout acceptance against the 1.x strict wrapped validator; and
- failure atomicity for malformed layout and insufficient output.
Run the checkpoint on the active toolchain and MSRV with:
```sh
scripts/check-2.0-line-wrapping.sh
BASE64_NG_LINE_WRAP_TOOLCHAIN=1.90.0 \
scripts/check-2.0-line-wrapping.sh
```