#lattice #macro #merge #derive #generics #field #lattice-ord

macro lattices_macro

Procedural macros for the lattices crate

3 releases

0.5.7 Nov 8, 2024
0.5.6 Aug 30, 2024
0.5.5 Jul 23, 2024

#1798 in Procedural macros

Download history 2/week @ 2024-08-23 153/week @ 2024-08-30 13/week @ 2024-09-06 37/week @ 2024-09-13 37/week @ 2024-09-20 22/week @ 2024-09-27 8/week @ 2024-10-04 13/week @ 2024-10-11 5/week @ 2024-10-18 1/week @ 2024-10-25 7/week @ 2024-11-01 117/week @ 2024-11-08 16/week @ 2024-11-15 12/week @ 2024-11-22 18/week @ 2024-11-29 36/week @ 2024-12-06

84 downloads per month
Used in 9 crates (via lattices)

Apache-2.0

22KB
466 lines

#[derive(Lattice)] Macro

A struct of multiple lattices can form a product lattice. The simplest case of this is the Pair lattice, which is a product of two sub-lattices. For more than two lattices, and/or to improve readability, users can create their own product lattice structs, where each field is a sub-lattice, and use the #[derive(Lattice)] macro to automatically derive the lattice traits.

Derives Merge, PartialEq, PartialOrd, LatticeOrd, IsBot, IsTop, and LatticeFrom, and therefore Lattice too. Alternatively, individual traits can be derived: #[derive(Merge, LatticeOrd, IsBot, IsTop, LatticeFrom)]. Note that LatticeOrd also derives PartialEq and PartialOrd.

Note that all fields must be lattice types. If any field cannot be a lattice type then the where clauses prevent the trait impl from compiling.

These derive macros will create a second set of generics to allow conversion and merging between varying types. For example, given this struct:

#[derive(Lattice)]
struct MyLattice<KeySet, Epoch>
where
    KeySet: Collection,
    Epoch: Ord,
{
    keys: SetUnion<KeySet>,
    epoch: Max<Epoch>,
}

Will create derive macros impls in the form:

impl<KeySet, Epoch, KeySetOther, EpochOther>
    Merge<MyLattice<KeySetOther, EpochOther>> for MyLattice<KeySet, Epoch>
where
    KeySet: Collection,
    Epoch: Ord,
    KeySetOther: Collection,
    EpochOther: Ord,
{
    // ...
}

Dependencies

~3MB
~56K SLoC