Skip to main content

impl_request_has_field

Macro impl_request_has_field 

Source
macro_rules! impl_request_has_field {
    (
        $type:ty,
        $wrapper:ident,
        $wrapper_field:ident,
        $(
            $trait:ident, $method:ident, &$ret:ty, $field:ident;
        )+
    ) => { ... };
    (
        $type:ty,
        $wrapper:ident,
        $wrapper_field:ident,
        $(
            $trait:ident, $method:ident, $ret:ty, $field:ident;
        )+
    ) => { ... };
}
Expand description

Generates Has* request-field trait implementations for a base payload type and its wrapper.

This macro is intended for SDK extension points where wrapper composition must preserve access to request fields through nested With* types.

Supported form:

use openpit::{HasInstrument, Instrument, impl_request_has_field};
use openpit::param::Asset;

#[derive(Clone)]
struct BaseOrder {
    instrument: Instrument,
}

struct WithOrder<T> {
    inner: T,
    order: BaseOrder,
}

impl_request_has_field!(
    BaseOrder,
    WithOrder,
    order,
    HasInstrument, instrument, &Instrument, instrument;
);

let instrument = Instrument::new(
    Asset::new("SPX").expect("must be valid"),
    Asset::new("USD").expect("must be valid"),
);
let wrapper = WithOrder {
    inner: (),
    order: BaseOrder {
        instrument: instrument.clone(),
    },
};

assert_eq!(wrapper.instrument(), Ok(&instrument));

Behavior:

  • Implements each listed Has* trait for the base type and the wrapper.
  • Wrapper methods delegate to self.<wrapper_field>.<method>().
  • All generated methods return Result<_, RequestFieldAccessError>.
  • Owned/copy return form clones the base field with self.<field>.clone().
  • Reference return form (&T) borrows the base field as &self.<field>.

Notes:

  • For fields that require custom conversion (for example Option<Asset> -> Option<&Asset>), provide a manual impl instead of this macro.