Skip to main content

CReprOf

Derive Macro CReprOf 

Source
#[derive(CReprOf)]
{
    // Attributes available to this derive:
    #[target_type]
    #[nullable]
    #[c_repr_of_convert]
    #[target_name]
}
Expand description

Derive CReprOf<T> for a struct or unit enum.

Generates a consuming conversion from the idiomatic Rust type named in #[target_type(...)] to Self. C-string fields (pointers to c_char) are re-allocated as CStrings, other pointer fields are boxed via RawPointerConverter::into_raw_pointer, and remaining fields go through their own CReprOf impl.

§Struct-level attributes

  • #[target_type(Path)]required. The idiomatic Rust type this #[repr(C)] struct mirrors.

§Field-level attributes

  • #[nullable] — required on every pointer field whose Rust counterpart is an [Option]. A None value is written as a null pointer.
  • #[target_name(ident)] — name of the matching field on the Rust side when it differs from the C-side name.
  • #[c_repr_of_convert(expr)] — replace the generated conversion with a custom expression. The owned Rust value input: TargetType is in scope. A field marked with this attribute is also skipped by the AsRust derive — if the reverse direction is needed, provide it with #[as_rust_extra_field(...)] on the struct.

§Enums

Enums are supported only if every variant is a unit variant.