#algebra #monoid

macro alga_derive

Derive attribute for implementing algebraic traits from the alga crate

10 releases

Uses old Rust 2015

0.9.2 Mar 2, 2020
0.9.1 May 11, 2019
0.9.0 Mar 31, 2019
0.7.1 Sep 13, 2018
0.5.0 Mar 29, 2017

#17 in #monoid

Download history 443/week @ 2023-11-29 468/week @ 2023-12-06 701/week @ 2023-12-13 612/week @ 2023-12-20 332/week @ 2023-12-27 358/week @ 2024-01-03 643/week @ 2024-01-10 595/week @ 2024-01-17 480/week @ 2024-01-24 343/week @ 2024-01-31 746/week @ 2024-02-07 737/week @ 2024-02-14 699/week @ 2024-02-21 731/week @ 2024-02-28 821/week @ 2024-03-06 518/week @ 2024-03-13

2,879 downloads per month
Used in 4 crates

Apache-2.0

23KB
426 lines

Build status

Documentation

alga-derive − automatic deriving of abstract algebra traits for Rust

alga-derive allows automatic deriving of traits provided by alga.

It supports deriving following alga traits:

  • AbstractQuasigroup
  • AbstractMonoid
  • AbstractSemigroup
  • AbstractGroup
  • AbstractGroupAbelian
  • AbstractRing
  • AbstractRingCommutative
  • AbstractField

The custom derive can also be used to generate quickcheck tests that check that algebraic properties are satisfied by the target of the derive.


lib.rs:

alga-derive

Custom derive for alga traits.

Supported traits:

  • AbstractQuasigroup
  • AbstractMonoid
  • AbstractSemigroup
  • AbstractGroup
  • AbstractGroupAbelian
  • AbstractRing
  • AbstractRingCommutative
  • AbstractField

Examples

extern crate alga;
#[macro_use]
extern crate alga_derive;

use alga::general::Additive;

#[derive(Alga)]
#[alga_traits(Group(Additive))]
struct Struct;

This derive implements AbstractGroup marker trait with Additive operator and all marker traits required by the algebraic groupness property (AbstractMonoid, AbstractSemigroup, AbstractLoop and AbstractQuasigroup) for the target of the derive.

Traits required by these marker traits (Identity, PartialEq, TwoSidedInverse and AbstractMagma) should be implemented manually.

If #[alga_quickcheck] attribute is added for the target of the derive, then quickcheck tests will be generated. These tests will check that the algebraic properties of the derived trait are true for the type. This attribute requires quickchecks Arbitrary trait to be implemented for the target of the derive.

extern crate alga;
#[macro_use]
extern crate alga_derive;

use alga::general::{Additive, AbstractGroup};

#[derive(Alga)]
#[alga_traits(Group(Additive), Where = "T: AbstractGroup")]
#[alga_quickcheck(check(i32), check(i64))]
struct Struct<T>;

When there is generic parameters on the target of the derive, then all the concrete type parameters that the tests are generated for can be specified in alga_quickcheck attribute by listing them in checks.

If bounds are required for the alga traits to be implemented, they can be listed by Where = "A: Bound1. B: Bound2".

Dependencies

~2MB
~46K SLoC