Skip to content

Replace numeric version field with Format enum#805

Merged
demoray merged 1 commit into
mainfrom
bcaswell/format-enum
May 21, 2026
Merged

Replace numeric version field with Format enum#805
demoray merged 1 commit into
mainfrom
bcaswell/format-enum

Conversation

@demoray
Copy link
Copy Markdown
Collaborator

@demoray demoray commented May 20, 2026

Replaces the bare u32 version field on Header and Image with an image::Format enum (Lime / AvmlCompressed).

The wire encoding (4-byte magic + 4-byte version) is unchanged, so existing .lime / .avml files read back identically.

API changes

  • image::Format enum, re-exported from the crate root.
  • Header { format } and Snapshot::format(Format) replace the integer version field / builder.
  • Image fields format and align_src are now pub(crate); src / dst remain pub for the convert binary's stream manipulation. Image::from_streams is the public constructor for non-file usage.
  • Header::encode is infallible; Header::write no longer propagates a version error.
  • Error::UnimplementedVersion is removed — UnsupportedFormat covers bad-magic / wrong-version pairs read from disk.
  • avml-convert renames its CLI value-enum to CliFormat to avoid collision with image::Format.

Why

Every format dispatch site (copy_if_nonzero, convert_block, convert_to_raw_image) is now exhaustive on the two variants — adding a v3 will force an update at each site instead of falling through an _ => Err(UnimplementedVersion) arm. Constructing an Image with an invalid version is no longer expressible.

Verified locally

  • cargo fmt
  • cargo clippy --locked --all-targets --all-features -- -D warnings -D clippy::pedantic -A clippy::missing_errors_doc
  • cargo test --all-features (28 lib + 2 convert + 1 doctest pass)

Header and Image now carry a Format (Lime / AvmlCompressed) instead of
a u32 version. The wire encoding (4-byte magic + 4-byte version) is
unchanged, so on-disk .lime / .avml files read back identically.

API changes:
- image::Format enum, re-exported from the crate root
- Header { format } and Snapshot::format(Format) replace the integer
  version field/builder
- Image fields format and align_src are now pub(crate); src/dst remain
  pub for the convert binary's stream manipulation. Image::from_streams
  is the public constructor for non-file usage
- Header::encode is infallible; Header::write no longer propagates a
  version error
- Error::UnimplementedVersion is removed (UnsupportedFormat covers
  bad-magic / wrong-version pairs from disk)
- avml-convert renames its CLI value-enum to CliFormat to avoid
  collision with image::Format

Every format dispatch site (copy_if_nonzero, convert_block,
convert_to_raw_image) is now exhaustive on the two variants.
@demoray demoray force-pushed the bcaswell/format-enum branch from 6fd02a5 to cc6e35d Compare May 21, 2026 15:38
@demoray demoray enabled auto-merge (squash) May 21, 2026 15:38
@demoray demoray merged commit 0ef91ee into main May 21, 2026
8 checks passed
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.

2 participants