From fcd956974ab04f07a8b12ae838ae2620154ff89d Mon Sep 17 00:00:00 2001 From: Mark Karpeles Date: Mon, 15 Jun 2026 02:49:19 +0900 Subject: [PATCH] =?UTF-8?q?fix(lzma2):=20restore=20Debug/Clone=20on=20Enco?= =?UTF-8?q?der;=20document=20the=20stub=E2=86=92struct=20break?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The raw LZMA2 encoder (added in the previous release cycle) turned the former permanently-`Unsupported` `lzma2::Encoder` unit-struct stub into a real stateful encoder. cargo-semver-checks flagged four API changes; two of them — the dropped `Debug` and `Clone` derives — were an oversight, not inherent to the change. - Re-derive `Debug` + `Clone` on `lzma2::Encoder` (and add `Debug` to the internal `EncoderParams` so the derive composes). - Document, in the type docs and the CHANGELOG, that the encoder is now a stateful struct and intentionally no longer `Copy` / no longer a unit struct — the two remaining, unavoidable breaking changes (a buffering encoder cannot be a zero-sized `Copy` type). These drive the next minor (0.7.0) release per pre-1.0 semver. No behavior change; full suite, fmt, clippy, and docs remain green. Co-Authored-By: Claude Fable 5 --- CHANGELOG.md | 6 ++++++ src/lzma2/mod.rs | 5 +++++ src/lzma2_internal/lzma2_encoder.rs | 2 +- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f6cfdb..94b4956 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- **Breaking:** `compcol::lzma2::Encoder` is now a normal (stateful) struct + instead of the former permanently-`Unsupported` unit-struct stub, because the + working encoder buffers chunk state. As a result it **no longer implements + `Copy`** and can no longer be constructed via a unit-struct literal; construct + it through `Lzma2::encoder()` as with every other codec. It still derives + `Debug` + `Clone`. (No effect on the decoder or any other codec.) - **lz5 (Lizard) Huffman sub-streams** stay `Unsupported`, now with a precise rationale in the module docs: the Huff0 entropy stage selects X1/X2 from `(regenSize, comprLen)` at runtime and there is no reference encoder or diff --git a/src/lzma2/mod.rs b/src/lzma2/mod.rs index 41eb5ba..44d06cc 100644 --- a/src/lzma2/mod.rs +++ b/src/lzma2/mod.rs @@ -225,6 +225,11 @@ enum EncPhase { /// (dict + props + state) at the chunk boundary, emitting a compressed chunk /// (control `0xE0`) when that shrinks the data and an uncompressed chunk /// (control `0x01`) otherwise. +/// +/// Note: unlike the former permanently-`Unsupported` stub (a unit struct), +/// the working encoder buffers state, so it is a normal struct and is no +/// longer `Copy` — construct it via [`Lzma2::encoder()`](crate::Algorithm). +#[derive(Debug, Clone)] pub struct Encoder { phase: EncPhase, /// Staged bytes for the current chunk (or end marker), drained to the diff --git a/src/lzma2_internal/lzma2_encoder.rs b/src/lzma2_internal/lzma2_encoder.rs index bf1ad94..69dadd4 100644 --- a/src/lzma2_internal/lzma2_encoder.rs +++ b/src/lzma2_internal/lzma2_encoder.rs @@ -103,7 +103,7 @@ const NIL: u32 = u32::MAX; /// raise `nice_match` (the length at which the chain walk gives up and /// accepts the current match). This is the same speed-vs-ratio knob that /// xz-utils exposes — we just expose a small subset. -#[derive(Clone, Copy)] +#[derive(Debug, Clone, Copy)] pub(crate) struct EncoderParams { pub max_chain: usize, pub nice_match: u32,