Crate algebra_core_derive

Crate algebra_core_derive 

Source
Expand description

§algebra-core-derive — procedural macros for algebraic traits

Part of the postbox workspace

This crate provides derive macros for the algebra-core library, enabling boilerplate-free implementations of algebraic traits for product types (structs with named or unnamed fields).

§Supported derives

§Semigroup hierarchy

  • #[derive(Semigroup)] — implements combine by combining each field
  • #[derive(Monoid)] — implements empty() by calling empty() on each field
  • #[derive(CommutativeMonoid)] — marker trait requiring Monoid
  • #[derive(Group)] — implements inverse by inverting each field
  • #[derive(AbelianGroup)] — marker trait requiring Group + CommutativeMonoid

§Join-semilattice hierarchy

  • #[derive(JoinSemilattice)] — implements join by joining each field
  • #[derive(BoundedJoinSemilattice)] — implements bottom() by calling bottom() on each field

§Meet-semilattice hierarchy

  • #[derive(MeetSemilattice)] — implements meet by meeting each field
  • #[derive(BoundedMeetSemilattice)] — implements top() by calling top() on each field

§Usage

These macros are re-exported through algebra-core when the derive feature is enabled:

use algebra_core::{Semigroup, Monoid, JoinSemilattice, BoundedJoinSemilattice};

#[derive(Clone, PartialEq, Eq, Debug)]
#[derive(Semigroup, Monoid, JoinSemilattice, BoundedJoinSemilattice)]
struct MyLattice {
    counter: algebra_core::Max<i32>,
    tags: std::collections::HashSet<String>,
}

Each derive macro generates efficient componentwise implementations following standard product algebra semantics.

Derive Macros§

AbelianGroup
Derive macro for AbelianGroup.
BoundedJoinSemilattice
Derive macro for BoundedJoinSemilattice.
BoundedMeetSemilattice
Derive macro for BoundedMeetSemilattice.
CommutativeMonoid
Derive macro for CommutativeMonoid.
Group
Derive macro for Group.
JoinSemilattice
Derive macro for JoinSemilattice.
MeetSemilattice
Derive macro for MeetSemilattice.
Monoid
Derive macro for Monoid.
Semigroup
Derive macro for Semigroup.