Skip to content

feat(embed): const constructors, output accessors and owned tables in flate - #137

Merged
MagicalTux merged 1 commit into
masterfrom
embed-flate-const
Oct 3, 2026
Merged

MagicalTux merged 1 commit into
masterfrom
embed-flate-const

Conversation

@MagicalTux

Copy link
Copy Markdown
Member

What

Ports minizlib's last two commits into embed::flate. Without them, the minizlib 0.1.1 → re-export switch (KarpelesLab/minizlib#5) would lose API that minizlib's master has gained.

  • const fn new on Decompressor and Compressor. Given an output and a table that start as all zeros, a new codec is all zeros too, so it can live in a static in .bss and costs no flash. The position where the stream starts is now read on first use, since a const fn can't ask the output for it.
  • output() / output_mut() on both, so the caller can drain their own Output between pieces.
  • Owned tables: Compressor<'t, O, F, T = &'t mut [u16]> accepts any T: AsMut<[u16]>, e.g. [0u16; 4096]. The default type parameter keeps existing code compiling.
  • Shared checksums: adds Container::INIT. flate now uses embed's own CRC-32 and Adler-32, which start from all zeros like minizlib's do now, and drops its own copy.

After folding the feature gates the same way as in #135, the ported files are identical to minizlib's master, apart from removing dead branches.

Footprint

configuration code was ceiling
Decompressor 3424 3460 3650
gzip, buffer out 1030 982 1050 → 1100
Compressor, streams 1404 1344 1450 → 1500
BufferedCompressor 1600 1522 1600 → 1700

No panic machinery is linked. The ceilings were raised to restore about 5% headroom.

Tests

New tests/embed_flate_embedding.rs, added to CI's embed test step:

  • both codecs built in statics and reused;
  • an owned table produces the same stream as a borrowed one;
  • output drained between pieces.

These pass locally:

  • fmt;
  • clippy on --features all, --all-features, embed,gzip and embed;
  • rustdoc with -D warnings;
  • cargo test --all-features and the embed test step;
  • the thumbv7em build;
  • the MSRV 1.88 check;
  • tools/footprint/check.sh.

🤖 Generated with Claude Code

… `flate`

Brings `embed::flate` up to date with minizlib's last two commits, so that
minizlib can re-export it without losing API:

- `Decompressor::new` and `Compressor::new` are `const fn`, and their
  initial state is all zeros (given an output and table that are), so one
  can live in a `static` in `.bss`; the stream's start is taken on first
  use rather than in `new`.
- `output()` / `output_mut()` on both, to drain an output between pieces.
- `Compressor<'t, O, F, T = &'t mut [u16]>`: the table may be owned, any
  `T: AsMut<[u16]>`.
- `Container::INIT`; `flate` now shares `embed`'s zero-based CRC-32 and
  Adler-32 instead of keeping its own.

Test: the codecs in `static`s, owned vs borrowed tables, outputs drained
between pieces. Footprint ceilings for `gzip`, `Compressor` and
`BufferedCompressor` raised to keep headroom (1030, 1404 and 1600 bytes).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@MagicalTux
MagicalTux merged commit 9d63f01 into master Oct 3, 2026
48 checks passed
@MagicalTux MagicalTux mentioned this pull request Oct 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant