#[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:
- Generates the necessary wiring to support calling
linked::new!
in constructors to create instances. This macro disables regularSelf {}
struct-expressions and requires the use oflinked::new!
. - Implements
Clone
for the struct. All linked objects can be cloned to create new instances linked to the same family. - Implements the trait
linked::Object
for the struct, enabling standard linked object pattern mechanisms such as calling.family()
on instances to access theFamily
. - Implements
From<linked::Family<T>>
for the struct. This allows converting aFamily
into an instance of the linked object using.into()
.
§Constraints
Only structs defined in the named fields form are supported (no tuple structs).