| Crates.io | subtype_macro |
| lib.rs | subtype_macro |
| version | 0.2.1 |
| created_at | 2025-07-30 19:44:02.603497+00 |
| updated_at | 2025-10-14 12:23:58.550287+00 |
| description | Ada‑style subtype attribute macro for Rust |
| homepage | https://github.com/Feralthedogg/subtype_macro |
| repository | https://github.com/Feralthedogg/subtype_macro |
| max_upload_size | |
| id | 1773960 |
| size | 35,006 |
Formal enum-mode support + stronger struct-mode transparency. #[subtype] now works on C-like enums with an explicit integer #[repr(..)]. In struct mode, the macro auto-adds #[repr(transparent)] to improve FFI/ABI guarantees. Crate-level docs and examples were expanded.
Enum mode (requires an integer #[repr(u8) | u16 | …]):
Common impls: Display (numeric), From<Enum> for repr, and to_repr().
TryFrom<repr>:
unsafe transmute.match over known discriminants.Custom error type: error = "path::ToErr" or error(path::ToErr). If omitted, a lightweight <EnumName>TryFromError is generated.
Crate-level documentation (//! …):
Struct mode #[repr(transparent)] auto-insertion:
Improved diagnostics:
#[repr(..)].error(...) arguments.Helper refactor:
is_primitive_integer_ident for readability.MIN/MAX, new, into_inner, to_repr, etc.).Enum fast path:
transmute only after verifying MIN <= x <= MAX, which makes the cast sound.Struct-mode FFI/ABI:
#[repr(transparent)] strengthens compatibility with C ABIs.#[subtype] on enums, you must specify a primitive integer #[repr(..)] (e.g., #[repr(u8)]).From<subtype_rs::SubtypeError<ReprOrInner>>.#[repr(transparent)]. This is typically desirable; review only if you relied on a non-transparent layout for unusual reasons.