macro_rules! generate_slot_range {
    ($( $x:ident ( $e:expr ) ),*) => { ... };
    (@inner
		{ $( $parsed:ident ( $t1:expr, $t2:expr ) )* }
		$current:ident ( $ce:expr )
		$( $remaining:ident ( $re:expr ) )*
	) => { ... };
    (@inner
		{ $( $parsed:ident ( $t1:expr, $t2:expr ) )* }
	) => { ... };
}
Expand description

This macro generates a SlotRange enum of arbitrary length for use in the Slot Auction mechanism on Polkadot.

Usage:

slot_range_helper::generate_slot_range!(Zero(0), One(1), Two(2), Three(3));

To extend the usage, continue to add Identifier(value) items to the macro.

This will generate an enum SlotRange with the following properties:

  • Enum variants will range from all consecutive combinations of inputs, i.e. ZeroZero, ZeroOne, ZeroTwo, ZeroThree, OneOne, OneTwo, OneThree
  • A constant LEASE_PERIODS_PER_SLOT will count the number of lease periods.
  • A constant SLOT_RANGE_COUNT will count the total number of enum variants.
  • A function as_pair will return a tuple representation of the SlotRange.
  • A function intersects will tell you if two slot ranges intersect with one another.
  • A function len will tell you the length of occupying a SlotRange.
  • A function new_bounded will generate a SlotRange from an input of the current lease period, the starting lease period, and the final lease period.