Attribute Macro object

Source
#[object]
Expand description

Marks a struct as implementing the linked object pattern.

See package-level documentation for a high-level guide.

§Usage

Apply the attribute on a struct block. Then, in constructors, use the linked::new! macro to create an instance of the struct.

§Example

#[linked::object]
pub struct TokenCache {
    some_value: usize,
}

impl TokenCache {
    pub fn new(some_value: usize) -> Self {
        linked::new!(Self { some_value })
    }
}

§Effects

Applying this macro has the following effects:

  1. Generates the necessary wiring to support calling linked::new! in constructors to create instances. This macro disables regular Self {} struct-expressions and requires the use of linked::new!.
  2. Implements Clone for the struct. All linked objects can be cloned to create new instances linked to the same family.
  3. Implements the trait linked::Object for the struct, enabling standard linked object pattern mechanisms such as calling .family() on instances to access the Family.
  4. Implements From<linked::Family<T>> for the struct. This allows converting a Family into an instance of the linked object using .into().

§Constraints

Only structs defined in the named fields form are supported (no tuple structs).