simple_endian_derive

Crates.iosimple_endian_derive
lib.rssimple_endian_derive
version0.4.10
created_at2026-01-02 23:32:45.040441+00
updated_at2026-01-06 09:38:04.331699+00
descriptionProc-macros for the simple_endian crate.
homepage
repositoryhttps://github.com/rexlunae/simple-endian-rs
max_upload_size
id2019341
size65,464
Erica Stith (rexlunae)

documentation

README

simple_endian_derive

This crate provides the proc-macro implementation behind #[derive(Endianize)] for the simple_endian crate.

You generally should not depend on this crate directly. Enable the derive feature on simple_endian instead, which re-exports the derive macro.

Usage

In your Cargo.toml:

[dependencies]
simple_endian = { version = "0.4", features = ["derive"] }

Then:

use simple_endian::Endianize;

#[derive(Endianize)]
#[endian(le)]
#[repr(C)]
struct Header {
    magic: u32,
    version: u16,
}

// Generated by the macro:
// - `HeaderWire` (wire-format representation)

What gets generated

For a type named T, the macro generates a TWire companion type whose fields are endian-aware and whose layout is intended for IO.

The recommended workflow in the simple_endian ecosystem is native-first:

  • Use the native types in your application logic.
  • Convert at boundaries by reading/writing TWire (or using read_native / write_native when io-std is enabled).

Supported helper attributes

Container-level

  • #[endian(le)] / #[endian(be)] (required)
  • #[wire_repr(...)] – controls the generated wire type representation (e.g. #[repr(C)], #[repr(C, packed)])
  • #[wire_derive(...)] – derives to apply to the generated *Wire type
  • #[wire_default] / #[wire_default(...)] – controls Default generation for wire types

Field-level

  • #[text(...)] – fixed-size text fields (feature-gated by simple_endian text features)
  • #[tuple_text] – support for tuple enum variants in text contexts

Important limitation: enum wire derives

Enum wire types are represented as tag + union payload to match on-wire layout. Unions cannot derive many common traits (notably Debug, PartialEq, Eq, Hash, ...).

If you apply #[wire_derive(...)] to an enum, keep those restrictions in mind. In most cases you should keep derives on the native enum (where they make semantic sense), and convert at IO boundaries.

Repository / contributing

This crate is maintained in the simple-endian-rs repository alongside the main library crate.

Commit count: 103

cargo fmt