FieldRef

Trait FieldRef 

Source
pub trait FieldRef<T> {
    // Required method
    fn path(&self) -> &'static str;

    // Provided method
    fn get_ref<'a>(&self, _source: &'a T) -> Option<&'a T> { ... }
}
Expand description

Trait for direct field references - legacy approach (still supported)

This trait enables compile-time field name extraction and type checking. Use the field! macro to create field references directly from struct fields.

§Example

struct TradingMetrics {
    total_volume: u64,
    trade_count: u64,
}

// Use fields directly with the field! macro
let volume = ctx.get(&field!(entity, total_volume));
ctx.set(&field!(entity, total_volume), 1000);
ctx.increment(&field!(entity, trade_count), 1);

Required Methods§

Source

fn path(&self) -> &'static str

Get the field path (e.g., “total_volume”)

Provided Methods§

Source

fn get_ref<'a>(&self, _source: &'a T) -> Option<&'a T>

Get the field value from a reference (for type inference)

Implementors§