Expand description
Derive macros for the ommx crate.
This crate exists solely as an implementation detail of ommx: it
is published to crates.io because ommx depends on it, but it has no
stable API of its own and no public surface for external use.
The ommx crate gates the LogicalMemoryProfile trait and the
re-exported derive behind a pub(crate) module, so downstream users
cannot reach them through the public API and cannot meaningfully
derive on their own types. The trait and the re-export are declared
pub inside that module to satisfy the private_bounds lint when
the trait appears in the bound of a pub type within the crate
(e.g. ConstraintMetadataStore<ID: ... + LogicalMemoryProfile>).
External consumers should use
ommx::Instance::logical_memory_profile and
ommx::MemoryProfile instead.
§#[derive(LogicalMemoryProfile)]
Generates a LogicalMemoryProfile impl that delegates to each field
of a named-field struct. Each field is emitted under the path frame
"TypeName.field_name". The ommx crate uses this derive at every
struct definition that participates in memory profiling, so that
adding or removing a field automatically adjusts the profile.
§Supported
- Structs with named fields.
- All fields must implement
LogicalMemoryProfile. Primitives,String,Option<T>,Vec<T>,BTreeMap,HashMap,FnvHashMap, andBTreeSetall have blanket impls inommx::logical_memory::collections.
- All fields must implement
- Generic structs: type parameters are propagated through, but
no
LogicalMemoryProfilebound is added automatically. The struct must declare its ownwhere T: LogicalMemoryProfileclause. This matchesserde’s historical#[serde(bound = ...)]philosophy — the derive does not guess.
§Not supported
- Tuple structs and unit structs → emit a
compile_error!directing the caller to a hand-written impl. - Enums → emit a
compile_error!. For enums, hand-write amatch(Functionin theommxcrate is an example). - Field skipping → there is no
#[logical_memory(skip)]attribute. If a field truly should not participate, hand-write the impl. - Custom frame names → the frame is always
"TypeName.field_name"taken from the struct ident and field ident. For a renamed frame (e.g. when wrapping an external type), use the declarativeimpl_logical_memory_profile! { path::to::Type as "Name" { ... } }form instead.
§Testing
The proc-macro entry point delegates to
derive_logical_memory_profile_impl, a pure
TokenStream2 -> TokenStream2 function. This is exercised by inline
insta snapshot tests in this crate — the generated code is checked
in as a snapshot so any drift is caught at review time.
Derive Macros§
- Logical
Memory Profile - Derive
LogicalMemoryProfilefor a struct by delegating to each field.