Skip to main content

structible

Attribute Macro structible 

Source
#[structible]
Expand description

Transforms a struct into a map-backed type with generated accessors.

§Example

use structible::structible;

#[structible(HashMap)]
pub struct Person {
    pub name: String,
    pub age: u32,
    pub email: Option<String>,
}

This generates:

  • A field enum for map keys (one variant per field)
  • A value enum for map values (wrapping each field type)
  • A PersonFields struct for ownership extraction
  • The Person struct backed by HashMap
  • Getters, setters, and removers for each field

§Optional Fields

Fields typed as Option<T> are stored without the Option wrapper. Presence in the map represents Some, absence represents None:

  • email() returns Option<&String>
  • set_email(v) inserts the value
  • remove_email() removes and returns the value if present

§Required Fields

Non-optional fields are guaranteed present after construction:

  • name() returns &String (not Option)
  • set_name(v) replaces the value
  • Use into_fields() then take_name() to extract owned value