# `simple_endian_derive`
This crate provides the proc-macro implementation behind `#[derive(Endianize)]` for the [`simple_endian`](https://crates.io/crates/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`:
```toml
[dependencies]
simple_endian = { version = "0.4", features = ["derive"] }
```
Then:
```rust
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.