Macro find_in_tracker

Source
macro_rules! find_in_tracker {
    {
    // This `+` is needed because otherwise it's LL1-ambiguous and macro_rules can't cope
    $enabled:expr;
    $tracker_input:expr => $( + $tracker:ident, )? $state:ident;
    $aid:expr => $arecord:ident;
 $( $pid:expr => $precord:ident; )?
    // Either `Error` or None, to be passed to `find_in_tracker_eh!($eh ...: ...)`
    // (We need this to be an un-repeated un-optional binding, because
    // it is used within some other $( ... )?, and macro_rules gets confused.)
    ? $eh:tt
} => { ... };
}
Expand description

Given a &Weak<MemoryQuotaTracker>, find an account and maybe participant

§Usage templates

find_in_tracker! {
    enabled;
    weak_tracker => + tracker, state;
    aid => arecord;
  [ pid => precord; ]
  [ ?Error | ?None ]
};

find_in_tracker! {
    enabled;
    strong_tracker => state;
    .. // as above
};

§Input expressions (value arguments to the macro0

  • weak_tracker: &Weak<MemoryQuotaTracker> (or equivalent)
  • strong_tracker: &MemoryQuotaTracker (or equivalent)
  • enabled: EnabledToken (or equivalent)
  • aid: AId
  • pid: PId

§Generated bindings (identifier arguments to the macro)

  • tracker: Arc<MemoryQuotaTracker>
  • state: &mut State (borrowed from a MutexGuard<State> borrowed from tracker)
  • arecord: &mut ARecord (mut borrowed from state.accounts)
  • precord: &mut PRecord (mut borrowed from arecord.ps)

There is no access to the MutexGuard itself. For control of the mutex release point, place find_in_tracker! in an enclosing block.

§Error handling

If the tracker, account, or participant, can’t be found, the macro returns early from the enclosing scope (using ?).

If Error is specified, applies ? to Err(Error::...). If None is specified, just returns None (by applying ? to None`).