Skip to main content

FromExtensions

Derive Macro FromExtensions 

#[derive(FromExtensions)]
Expand description

Derive a from_extensions constructor that gathers extension pieces from a rama_core::extensions::Extensions store in a single pass.

On a struct, each named field must be Option<&'a T> (borrowed) or Option<Arc<T>> (owned Arc clone), and the two may be mixed. A field may also be Option<(&'a T, usize)> / Option<(Arc<T>, usize)> to additionally capture the entry’s traversal rank (0 is the newest value seen, growing for older ones, so ranks order fields by recency). A borrowed field requires the struct to carry the matching lifetime (struct View<'a>); an all-Arc struct needs no lifetime. Generates fn from_extensions(ext: &Extensions) -> Self, where each field uses the same lookup as Extensions::get_ref but the store is traversed only once.

A rank is a completely opaque type and should only be used to compare positions, it does not tell anything about the absolute position.

On an enum, each variant is a one-field tuple variant naming a candidate type (Variant(&'a T) or Variant(Arc<T>), optionally Variant((&'a T, usize))). Generates fn from_extensions(ext: &Extensions) -> Option<Self> which returns the candidate inserted most recently (newest-wins by traversal rank), or None if none are present. If two variants name the same type the tie is broken deterministically in favour of the earlier declared variant.